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

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

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

BufferedImage.<init>介绍

[英]PBP: Placeholder to hide constructor.
[中]PBP:隐藏构造函数的占位符。

代码示例

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

private static BufferedImage createImage (int width, int height, Color color) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g = image.createGraphics();
    g.setColor(color);
    g.fillRect(0, 0, width, height);
    g.dispose();
    return image;
  }
}

代码示例来源: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: 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: Bukkit/Bukkit

/**
 * Resize an image to 128x128.
 *
 * @param image The image to resize.
 * @return The resized image.
 */
public static BufferedImage resizeImage(Image image) {
  BufferedImage result = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
  Graphics2D graphics = result.createGraphics();
  graphics.drawImage(image, 0, 0, 128, 128, null);
  graphics.dispose();
  return result;
}

代码示例来源:origin: dieforfree/qart4j

public static BufferedImage loadImage(String filename, int width, int height) throws IOException, ImageReadException {
  File file = new File(filename);
  BufferedImage image = ImageIO.read(file);
  //BufferedImage image = Imaging.getBufferedImage(file);
  //This was the reason jpeg was not supported. ImageIO handles the type conversion for us.
  BufferedImage finalImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  Graphics graphics = finalImage.createGraphics();
  graphics.drawImage(image, 0, 0, width, height, null);
  graphics.dispose();
  return finalImage;
}

代码示例来源:origin: org.apache.poi/poi

int y = findTruncatedBlackBox(img, width, height);
              if (y < height) {
                BufferedImage argbImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                Graphics2D g = argbImg.createGraphics();
                g.clipRect(0, 0, width, y);
                g.drawImage(img, 0, 0, null);
                g.dispose();
                img.flush();
                img = argbImg;
BufferedImage argbImg = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = argbImg.getGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
return argbImg;

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

BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
Font font = new Font("Arial", Font.PLAIN, 48);
g2d.setFont(font);
int width = fm.stringWidth(text);
int height = fm.getHeight();
g2d.dispose();
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
g2d = img.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.BLACK);
g2d.drawString(text, 0, fm.getAscent());
g2d.dispose();
try {
  ImageIO.write(img, "png", new File("Text.png"));

代码示例来源:origin: jphp-group/jphp

@Override
  public PImage __clone(Environment env, TraceInfo trace) {
    BufferedImage copyOfImage =
        new BufferedImage(getWidth(), getHeight(), image.getType());
    Graphics g = copyOfImage.createGraphics();
    g.drawImage(image, 0, 0, null);

    return new PImage(env, copyOfImage);
  }
}

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

/**
 * Copy an image
 * @param src
 * @return
 */
private static Image copy(Image src)
{
  final int width = src.getWidth(null);
  final int height = src.getHeight(null);
  BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  Graphics graphics = image.getGraphics();
  graphics.drawImage(src, 0, 0, width, height, null);
  graphics.dispose();
  return image;
}

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

private byte[] writeImageToBytes(Image image) throws IOException
{
  BufferedImage bi = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  Graphics2D g = bi.createGraphics();
  g.drawImage(image,0,0,width,height,null);
  ImageIO.write(bi,"jpg",baos);
  baos.close();
  bi = null;
  g = null;
  
  return baos.toByteArray();
}

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

private BufferedImage generateAtlas(int mipMapLevel, List<BlockTile> tileImages, Color clearColor) {
    int size = atlasSize / (1 << mipMapLevel);
    int textureSize = tileSize / (1 << mipMapLevel);
    int tilesPerDim = atlasSize / tileSize;

    BufferedImage result = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
    Graphics g = result.getGraphics();

    g.setColor(clearColor);
    for (int index = 0; index < tileImages.size(); ++index) {
      int posX = (index) % tilesPerDim;
      int posY = (index) / tilesPerDim;
      BlockTile tile = tileImages.get(index);
      if (tile != null) {
        g.drawImage(tile.getImage().getScaledInstance(textureSize, textureSize, Image.SCALE_SMOOTH), posX * textureSize, posY * textureSize, null);
      } else {
        g.fillRect(posX * textureSize, posY * textureSize, textureSize, textureSize);
      }
    }

    return result;
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

public SwingDirectGC( ImageObserver observer, Point area, int iconsize, int xOffset, int yOffset ) throws KettleException {
 this.image = new BufferedImage( area.x, area.y, BufferedImage.TYPE_INT_ARGB );
 this.gc = image.createGraphics();
 this.observer = observer;
 this.stepImages = SwingGUIResource.getInstance().getStepImages();
 this.entryImages = SwingGUIResource.getInstance().getEntryImages();
 this.iconsize = iconsize;
 this.area = area;
 this.xOffset = xOffset;
 this.yOffset = yOffset;
 init();
}

代码示例来源: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: stackoverflow.com

BufferedImage createResizedCopy(Image originalImage, 
     int scaledWidth, int scaledHeight, 
     boolean preserveAlpha)
 {
   System.out.println("resizing...");
   int imageType = preserveAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
   BufferedImage scaledBI = new BufferedImage(scaledWidth, scaledHeight, imageType);
   Graphics2D g = scaledBI.createGraphics();
   if (preserveAlpha) {
     g.setComposite(AlphaComposite.Src);
   }
   g.drawImage(originalImage, 0, 0, scaledWidth, scaledHeight, null); 
   g.dispose();
   return scaledBI;
 }

代码示例来源: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: runelite/runelite

final int newWidth = (int) (width * scale);
final int newHeight = (int) (height * scale);
final BufferedImage scaledImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
final Graphics g = scaledImage.createGraphics();
g.drawImage(image, 0, 0, newWidth, newHeight, null);
g.dispose();
resultImage = scaledImage;

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

new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR);
final Graphics2D g = image.createGraphics();
g.drawLine(50, 0, 50, imageHeight - 25);
g.dispose();

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

private BufferedImage convertToBufferedImage(Image image) throws IOException {
  if (image instanceof BufferedImage) {
    return (BufferedImage)image;
  } else {
    MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
    tracker.addImage(image, 0);
    try {
      tracker.waitForAll();
    } catch (InterruptedException e) {
      throw new IOException(e.getMessage());
    }
    BufferedImage bufImage = new BufferedImage(
        image.getWidth(null),
        image.getHeight(null),
        BufferedImage.TYPE_INT_ARGB);
    Graphics g = bufImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    return bufImage;
  }
}

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

private static BufferedImage createImage (int width, int height, Color color) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g = image.createGraphics();
    g.setColor(color);
    g.fillRect(0, 0, width, height);
    g.dispose();
    return image;
  }
}

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

/**
 * 高保真缩放
 */
private static BufferedImage resize(BufferedImage bi, int toWidth, int toHeight) {
  Graphics g = null;
  try {
    Image scaledImage = bi.getScaledInstance(toWidth, toHeight, Image.SCALE_SMOOTH);
    BufferedImage ret = new BufferedImage(toWidth, toHeight, BufferedImage.TYPE_INT_RGB);
    g = ret.getGraphics();
    g.drawImage(scaledImage, 0, 0, null);
    return ret;
  } catch (Exception e) {
    throw new RuntimeException(e);
  } finally {
    if (g != null) {
      g.dispose();
    }
  }
}

相关文章