java.awt.image.BufferedImage.getWidth()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(687)

本文整理了Java中java.awt.image.BufferedImage.getWidth()方法的一些代码示例,展示了BufferedImage.getWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedImage.getWidth()方法的具体详情如下:
包路径:java.awt.image.BufferedImage
类名称:BufferedImage
方法名:getWidth

BufferedImage.getWidth介绍

[英]Returns the width of the BufferedImage.
[中]返回[$0$]的宽度。

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
  public int compare (BufferedImage o1, BufferedImage o2) {
    return o2.getWidth() * o2.getHeight() - o1.getWidth() * o1.getHeight();
  }
});

代码示例来源:origin: javamelody/javamelody

private void addImage(BufferedImage img) {
  graphics.drawImage(img, x, alertOnHighUsage ? 4 : 0, null);
  x += img.getWidth();
}

代码示例来源:origin: libgdx/libgdx

public Rect (BufferedImage source, int left, int top, int newWidth, int newHeight, boolean isPatch) {
  image = new BufferedImage(source.getColorModel(),
    source.getRaster().createWritableChild(left, top, newWidth, newHeight, 0, 0, null),
    source.getColorModel().isAlphaPremultiplied(), null);
  offsetX = left;
  offsetY = top;
  regionWidth = newWidth;
  regionHeight = newHeight;
  originalWidth = source.getWidth();
  originalHeight = source.getHeight();
  width = newWidth;
  height = newHeight;
  this.isPatch = isPatch;
}

代码示例来源:origin: redwarp/9-Patch-Resizer

private BufferedImage trim9PBorder(BufferedImage inputImage) {
 BufferedImage trimedImage = new BufferedImage(
   inputImage.getWidth() - 2, inputImage.getHeight() - 2,
   BufferedImage.TYPE_INT_ARGB);
 Graphics2D g = trimedImage.createGraphics();
 g.drawImage(inputImage, 0, 0, trimedImage.getWidth(),
       trimedImage.getHeight(), 1, 1, inputImage.getWidth() - 1,
       inputImage.getHeight() - 1, null);
 g.dispose();
 return trimedImage;
}

代码示例来源:origin: JpressProjects/jpress

public static int[] ratio(String src) throws IOException {
  BufferedImage bufferedImage = ImageIO.read(new File(src));
  int width = bufferedImage.getWidth();
  int height = bufferedImage.getHeight();
  return new int[]{width, height};
}

代码示例来源:origin: MovingBlocks/Terasology

public void storeGreyscaleMapIntoAlpha(BufferedImage imageWithoutAlpha, BufferedImage greyscaleImage) {
  int width = imageWithoutAlpha.getWidth();
  int height = imageWithoutAlpha.getHeight();
  int[] imagePixels = imageWithoutAlpha.getRGB(0, 0, width, height, null, 0, width);
  int[] maskPixels = greyscaleImage.getRGB(0, 0, width, height, null, 0, width);
  for (int i = 0; i < imagePixels.length; i++) {
    int color = imagePixels[i] & 0x00ffffff; // Mask preexisting alpha
    int alpha = maskPixels[i] << 24; // Shift blue to alpha
    imagePixels[i] = color | alpha;
  }
  imageWithoutAlpha.setRGB(0, 0, width, height, imagePixels, 0, width);
}

代码示例来源:origin: stackoverflow.com

File path = ... // base path of the images

// load source images
BufferedImage image = ImageIO.read(new File(path, "image.png"));
BufferedImage overlay = ImageIO.read(new File(path, "overlay.png"));

// create the new image, canvas size is the max. of both image sizes
int w = Math.max(image.getWidth(), overlay.getWidth());
int h = Math.max(image.getHeight(), overlay.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(image, 0, 0, null);
g.drawImage(overlay, 0, 0, null);

// Save as new image
ImageIO.write(combined, "PNG", new File(path, "combined.png"));

代码示例来源:origin: kevin-wayne/algs4

image = ImageIO.read(file);
    url = new URL(filename);
  image = ImageIO.read(url);
width  = image.getWidth(null);
height = image.getHeight(null);
    Color color = new Color(image.getRGB(col, row));
    Color gray = toGray(color);
    image.setRGB(col, row, gray.getRGB());

代码示例来源:origin: stackoverflow.com

public static BufferedImage transformImage(BufferedImage image, AffineTransform transform) throws Exception {

  AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);

  BufferedImage destinationImage = op.createCompatibleDestImage(image, (image.getType() == BufferedImage.TYPE_BYTE_GRAY) ? image.getColorModel() : null );
  Graphics2D g = destinationImage.createGraphics();
  g.setBackground(Color.WHITE);
  g.clearRect(0, 0, destinationImage.getWidth(), destinationImage.getHeight());
  destinationImage = op.filter(image, destinationImage);
  return destinationImage;
}

代码示例来源:origin: nutzam/nutz

/**
 * 在一个RGB画布上重新绘制Image,解决CMYK图像偏色的问题
 */
public static BufferedImage redraw(BufferedImage img, Color bg) {
  BufferedImage rgbImage = new BufferedImage(img.getWidth(),
                        img.getHeight(),
                        BufferedImage.TYPE_3BYTE_BGR);
  Graphics2D g2d = rgbImage.createGraphics();
  g2d.drawImage(img, 0, 0, bg, null);
  g2d.dispose();
  return rgbImage;
}

代码示例来源:origin: JpressProjects/jpress

public static String ratioAsString(String src) throws IOException {
  File file = new File(src);
  if (!file.exists()) {
    return null;
  }
  BufferedImage bufferedImage = ImageIO.read(file);
  int width = bufferedImage.getWidth();
  int height = bufferedImage.getHeight();
  return String.format("%s x %s", width, height);
}

代码示例来源:origin: redwarp/9-Patch-Resizer

private void verifyBorderImage(BufferedImage border)
   throws Wrong9PatchException {
  int[] rgb = border.getRGB(0, 0, border.getWidth(), border.getHeight(),
               null, 0, border.getWidth());
  for (int i = 0; i < rgb.length; i++) {
   if ((0xff000000 & rgb[i]) != 0) {
    if (rgb[i] != 0xff000000 && rgb[i] != 0xffff0000) {
     throw new Wrong9PatchException();
    }
   }
  }
 }
}

代码示例来源:origin: libgdx/libgdx

public Rect (BufferedImage source, int left, int top, int newWidth, int newHeight, boolean isPatch) {
  image = new BufferedImage(source.getColorModel(),
    source.getRaster().createWritableChild(left, top, newWidth, newHeight, 0, 0, null),
    source.getColorModel().isAlphaPremultiplied(), null);
  offsetX = left;
  offsetY = top;
  regionWidth = newWidth;
  regionHeight = newHeight;
  originalWidth = source.getWidth();
  originalHeight = source.getHeight();
  width = newWidth;
  height = newHeight;
  this.isPatch = isPatch;
}

代码示例来源:origin: libgdx/libgdx

@Override
  public int compare (BufferedImage o1, BufferedImage o2) {
    return o2.getWidth() * o2.getHeight() - o1.getWidth() * o1.getHeight();
  }
});

代码示例来源:origin: stackoverflow.com

public static BufferedImage copyImage(BufferedImage source){
  BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
  Graphics g = b.getGraphics();
  g.drawImage(source, 0, 0, null);
  g.dispose();
  return b;
}

代码示例来源:origin: coobird/thumbnailator

public BufferedImage apply(BufferedImage img)
{
  int width = img.getWidth();
  int height = img.getHeight();
  
  BufferedImage finalImage =
    new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  
  Graphics2D g = finalImage.createGraphics();
  g.setComposite(composite);
  g.drawImage(img, 0, 0, null);
  g.dispose();
  
  return finalImage;
}

代码示例来源:origin: dcevm/dcevm

private JComponent getBanner() {
  try {
    BufferedImage img = ImageIO.read(getClass().getResource("splash.png"));
    JLabel title = new JLabel(new ImageIcon(img));
    title.setPreferredSize(new Dimension(img.getWidth() + 10, img.getHeight()));
    title.setOpaque(true);
    title.setBackground(new Color(238, 238, 255));
    return title;
  } catch (Exception ignore) {
  }
  return new JLabel();
}

代码示例来源:origin: stackoverflow.com

public static void makeGray(BufferedImage img)
{
  for (int x = 0; x < img.getWidth(); ++x)
  for (int y = 0; y < img.getHeight(); ++y)
  {
    int rgb = img.getRGB(x, y);
    int r = (rgb >> 16) & 0xFF;
    int g = (rgb >> 8) & 0xFF;
    int b = (rgb & 0xFF);

    int grayLevel = (r + g + b) / 3;
    int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel; 
    img.setRGB(x, y, gray);
  }
}

代码示例来源:origin: libgdx/libgdx

private void generatePremultiplyAlpha(File out){
  try {
    BufferedImage outImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    float[] color = new float[4];
    WritableRaster raster = image.getRaster();
    WritableRaster outRaster = outImage.getRaster();
    for(int x =0, w = image.getWidth(); x< w; ++x)
      for(int y =0, h = image.getHeight(); y< h; ++y){
        raster.getPixel(x, y, color);
        float alpha = color[3]/255f;
        for(int i=0;i < 3; ++i) 
          color[i] *= alpha;
        outRaster.setPixel(x, y, color);
      }
    ImageIO.write(outImage, "png", out);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
  public Dimension getPreferredSize () {
    Dimension dimension = super.getPreferredSize();
    if(image != null){
      dimension.width = image.getWidth();
      dimension.height = image.getHeight();
    }
    return dimension;
  }
}

相关文章