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; } }
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; }
/** * 在一个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; }
/** * 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; }
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; }
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;
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"));
@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); } }
/** * 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; }
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(); }
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; } }
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(); }
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; }
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; }
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; }
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;
new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR); final Graphics2D g = image.createGraphics(); g.drawLine(50, 0, 50, imageHeight - 25); g.dispose();
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; } }
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; } }
/** * 高保真缩放 */ 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(); } } }