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; }
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; }
private static BufferedImage deepCopy(BufferedImage bi) { final ColorModel cm = bi.getColorModel(); final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); final WritableRaster raster = bi.copyData(bi.getRaster().createCompatibleWritableRaster()); return new BufferedImage(cm, raster, isAlphaPremultiplied, null); } }
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM, int width, int height) { BufferedImage image; if (destCM == null) { destCM = src.getColorModel(); // Not much support for ICM if (destCM instanceof IndexColorModel) { destCM = ColorModel.getRGBdefault(); } } image = new BufferedImage (destCM, destCM.createCompatibleWritableRaster(width, height), destCM.isAlphaPremultiplied(), null); return image; }
ColorModel srcCM = src.getColorModel(); ColorModel dstCM; BufferedImage origDst = dst; src = icm.convertToIntDiscrete(src.getRaster(), false); srcCM = src.getColorModel(); dstCM = dst.getColorModel(); if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType()) dstCM = dst.getColorModel(); dstCM = dst.getColorModel();
@Override public void render(BufferedImage img, Region region) { FloraFacet treeFacet = region.getFacet(FloraFacet.class); Graphics2D g = img.createGraphics(); int width = img.getWidth(); ColorModel colorModel = img.getColorModel(); ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel); DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer(); for (Entry<BaseVector3i, FloraType> entry : treeFacet.getRelativeEntries().entrySet()) { FloraType treeGen = entry.getValue(); int wx = entry.getKey().getX(); int wz = entry.getKey().getZ(); Color color = colorFunc.apply(treeGen); int src = color.rgba(); int dst = dataBuffer.getElem(wz * width + wx); int mix = blender.blend(src, dst); dataBuffer.setElem(wz * width + wx, mix); } g.dispose(); }
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; }
private BufferedImage toCompatibleImage(BufferedImage image) { // obtain the current system graphical settings GraphicsConfiguration gfx_config = GraphicsEnvironment. getLocalGraphicsEnvironment().getDefaultScreenDevice(). getDefaultConfiguration(); /* * if image is already compatible and optimized for current system * settings, simply return it */ if (image.getColorModel().equals(gfx_config.getColorModel())) return image; // image is not optimized, so create a new image that is BufferedImage new_image = gfx_config.createCompatibleImage( image.getWidth(), image.getHeight(), image.getTransparency()); // get the graphics context of the new image to draw the old image on Graphics2D g2d = (Graphics2D) new_image.getGraphics(); // actually draw the image and dispose of context no longer needed g2d.drawImage(image, 0, 0, null); g2d.dispose(); // return the new optimized image return new_image; }
type = BufferedImage.TYPE_INT_ARGB; bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); return bimage.getColorModel().hasAlpha();
WritableRaster raster = offscreenImage.getRaster(); WritableRaster newRaster; newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[] {0, 1, 2}); DirectColorModel cm = (DirectColorModel) offscreenImage.getColorModel(); DirectColorModel newCM = new DirectColorModel(cm.getPixelSize(), cm.getRedMask(), cm.getGreenMask(), cm.getBlueMask()); BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null); try { ImageIO.write(rgbBuffer, suffix, file);
ICC_ColorSpace cmykCS = new ICC_ColorSpace(cmykProfile); BufferedImage rgbImage = new BufferedImage(cmykRaster.getWidth(), cmykRaster.getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster rgbRaster = rgbImage.getRaster(); ColorSpace rgbCS = rgbImage.getColorModel().getColorSpace(); ColorConvertOp cmykToRgb = new ColorConvertOp(cmykCS, rgbCS, null); cmykToRgb.filter(cmykRaster, rgbRaster);
@Override public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) { if (dstCM == null) dstCM = src.getColorModel(); return new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), dstCM.isAlphaPremultiplied(), null); }
private void extractAndSetBackgroundColor(final BufferedImage pImage) { // TODO: bgColor request attribute instead of parameter? if (pImage.getColorModel().hasAlpha()) { String bgColor = originalRequest.getParameter("bg.color"); if (bgColor != null) { Color color = StringUtil.toColor(bgColor); Graphics2D g = pImage.createGraphics(); try { g.setColor(color); g.setComposite(AlphaComposite.DstOver); g.fillRect(0, 0, pImage.getWidth(), pImage.getHeight()); } finally { g.dispose(); } } } }
public final BufferedImage createCompatibleDestImage(final BufferedImage pInput, final ColorModel pModel) { if (pInput == null) { throw new NullPointerException("pInput == null"); } ColorModel cm = pModel != null ? pModel : pInput.getColorModel(); // TODO: Might not work with all colormodels.. // If indexcolormodel, we probably don't want to use that... // NOTE: Either BOTH or NONE of the images must have ALPHA return new BufferedImage(cm, ImageUtil.createCompatibleWritableRaster(pInput, cm, width, height), cm.isAlphaPremultiplied(), null); }
WritableRaster raster = onscreenImage.getRaster(); WritableRaster newRaster; newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[] {0, 1, 2}); DirectColorModel cm = (DirectColorModel) onscreenImage.getColorModel(); DirectColorModel newCM = new DirectColorModel(cm.getPixelSize(), cm.getRedMask(), cm.getGreenMask(), cm.getBlueMask()); BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null); try { ImageIO.write(rgbBuffer, suffix, file);
WritableRaster rgbRaster = rgbImage.getRaster(); ColorSpace rgbCS = rgbImage.getColorModel().getColorSpace(); ColorConvertOp cmykToRgb = new ColorConvertOp(cmykCS, rgbCS, null); cmykToRgb.filter(cmykRaster, rgbRaster);
@Override public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) { if (dstCM == null) { dstCM = src.getColorModel(); } return new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), dstCM.isAlphaPremultiplied(), null); }
@Test public void testReadClipped() throws IOException { BufferedImage image = Paths.readClipped(resourceAsIIOStream("/jpeg/grape_with_path.jpg")); assertNotNull(image); // Same dimensions as original assertEquals(857, image.getWidth()); assertEquals(1800, image.getHeight()); // Transparent assertTrue(image.getColorModel().getTransparency() == Transparency.TRANSLUCENT); // Corners (at least) should be transparent assertEquals(0, image.getRGB(0, 0)); assertEquals(0, image.getRGB(image.getWidth() - 1, 0)); assertEquals(0, image.getRGB(0, image.getHeight() - 1)); assertEquals(0, image.getRGB(image.getWidth() - 1, image.getHeight() - 1)); // Center opaque assertEquals(0xff, image.getRGB(image.getWidth() / 2, image.getHeight() / 2) >>> 24); // TODO: Mor sophisticated test that tests all pixels outside path... }
public static BufferedImage deepCopy(BufferedImage bi) { ColorModel cm = bi.getColorModel(); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); WritableRaster raster = bi.copyData(null); return new BufferedImage(cm, raster, isAlphaPremultiplied, null); }
@Test public void testHandHotspotExplicitDestination() throws IOException { CURImageReader reader = createReader(); reader.setInput(getTestData().get(0).getInputStream()); BufferedImage image = reader.read(0); // Create dest image with same data, except properties... BufferedImage dest = new BufferedImage( image.getColorModel(), image.getRaster(), image.getColorModel().isAlphaPremultiplied(), null ); ImageReadParam param = new ImageReadParam(); param.setDestination(dest); assertHotSpot(getTestData().get(0), param, new Point(15, 15)); }