List of usage examples for java.awt.image BufferedImage getColorModel
public ColorModel getColorModel()
From source file:oct.util.Util.java
public static BufferedImage deepCopyBufferedImage(BufferedImage bi) { ColorModel cm = bi.getColorModel(); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); WritableRaster raster = bi.copyData(null); return new BufferedImage(cm, raster, isAlphaPremultiplied, null); }
From source file:net.rptools.lib.image.ImageUtil.java
public static int pickBestTransparency(BufferedImage image) { // See if we can short circuit ColorModel colorModel = image.getColorModel(); if (colorModel.getTransparency() == Transparency.OPAQUE) { return Transparency.OPAQUE; }/*from w ww .j a va2s . com*/ // Get the pixels int width = image.getWidth(); int height = image.getHeight(); // Look for specific pixels boolean foundTransparent = false; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // Get the next pixel int pixel = image.getRGB(x, y); int alpha = (pixel >> 24) & 0xff; // Is there translucency or just pure transparency ? if (alpha > 0 && alpha < 255) { return Transparency.TRANSLUCENT; } if (alpha == 0 && !foundTransparent) { foundTransparent = true; } } } return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE; }
From source file:de.bamamoto.mactools.png2icns.Scaler.java
public static BufferedImage resize(BufferedImage source, int width, int height) { double xScale = ((double) width) / (double) source.getWidth(); double yScale = ((double) height) / (double) source.getHeight(); BufferedImage result = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration()//from www.j a v a 2s . c om .createCompatibleImage(width, height, source.getColorModel().getTransparency()); Graphics2D newImage = null; try { newImage = result.createGraphics(); newImage.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); newImage.drawRenderedImage(source, AffineTransform.getScaleInstance(xScale, yScale)); } finally { if (newImage != null) { newImage.dispose(); } } return result; }
From source file:com.t3.image.ImageUtil.java
public static int pickBestTransparency(BufferedImage image) { // See if we can short circuit ColorModel colorModel = image.getColorModel(); if (colorModel.getTransparency() == Transparency.OPAQUE) { return Transparency.OPAQUE; }/*from w w w. jav a 2s . c o m*/ // Get the pixels int width = image.getWidth(); int height = image.getHeight(); // Look for specific pixels boolean foundTransparent = false; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // Get the next pixel int pixel = image.getRGB(x, y); int alpha = (pixel >> 24) & 0xff; // Is there translucency or just pure transparency ? if (alpha > 0 && alpha < 255) { return Transparency.TRANSLUCENT; } if (alpha == 0 && !foundTransparent) { foundTransparent = true; } } } return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE; }
From source file:ConvertUtil.java
/** * Converts the source to 1-bit colour depth (monochrome). No transparency. * /*from w w w. j a va2 s .c o m*/ * @param src * the source image to convert * @return a copy of the source image with a 1-bit colour depth. */ public static BufferedImage convert1(BufferedImage src) { IndexColorModel icm = new IndexColorModel(1, 2, new byte[] { (byte) 0, (byte) 0xFF }, new byte[] { (byte) 0, (byte) 0xFF }, new byte[] { (byte) 0, (byte) 0xFF }); BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_BINARY, icm); ColorConvertOp cco = new ColorConvertOp(src.getColorModel().getColorSpace(), dest.getColorModel().getColorSpace(), null); cco.filter(src, dest); return dest; }
From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactory.java
/** * Creates a new JPEG Image XObject from an input stream containing JPEG data. * /* w ww .j ava 2 s. c o m*/ * The input stream data will be preserved and embedded in the PDF file without modification. * * @param document the document where the image will be created * @param a JPEG file * @return a new Image XObject * * @throws IOException if the input stream cannot be read */ public static PDImageXObject createFromFile(File file) throws IOException { // read image BufferedImage awtImage = readJpegFile(file); // create Image XObject from stream PDImageXObject pdImage = new PDImageXObject(new BufferedInputStream(Files.newInputStream(file.toPath())), COSName.DCT_DECODE, awtImage.getWidth(), awtImage.getHeight(), awtImage.getColorModel().getComponentSize(0), getColorSpaceFromAWT(awtImage)); // no alpha if (awtImage.getColorModel().hasAlpha()) { throw new UnsupportedOperationException("alpha channel not implemented"); } return pdImage; }
From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java
public static boolean canDisplay(BufferedImage image) { log.info("Data Type: " + image.getSampleModel().getDataType()); log.info("Pixel Size: " + image.getColorModel().getPixelSize()); if (image.getSampleModel().getDataType() == DataBuffer.TYPE_FLOAT && image.getColorModel().getPixelSize() == 64) return false; return !GraphicsEnvironment.isHeadless(); }
From source file:org.gmdev.pdftrick.utils.CustomExtraImgReader.java
/** * Convert image from Cmyk to Rgb profile * @param cmykRaster/*from w w w .j a v a 2 s .c o m*/ * @param cmykProfile * @return The BufferedImage obj * @throws IOException */ private static BufferedImage convertCmykToRgb(Raster cmykRaster, ICC_Profile cmykProfile) throws IOException { if (cmykProfile == null) { cmykProfile = ICC_Profile.getInstance( CustomExtraImgReader.class.getResourceAsStream(Consts.RESOURCEPATH + Consts.GENERICICCFILE)); } if (cmykProfile.getProfileClass() != ICC_Profile.CLASS_DISPLAY) { byte[] profileData = cmykProfile.getData(); if (profileData[ICC_Profile.icHdrRenderingIntent] == ICC_Profile.icPerceptual) { intToBigEndian(ICC_Profile.icSigDisplayClass, profileData, ICC_Profile.icHdrDeviceClass); cmykProfile = ICC_Profile.getInstance(profileData); } } 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); return rgbImage; }
From source file:org.apache.fop.visual.BitmapComparator.java
/** * Builds a new BufferedImage that is the difference between the two input images * @param ref the reference bitmap//from w w w . j a v a 2 s. com * @param gen the newly generated bitmap * @return the diff bitmap */ public static BufferedImage buildDiffImage(BufferedImage ref, BufferedImage gen) { BufferedImage diff = new BufferedImage(ref.getWidth(), ref.getHeight(), BufferedImage.TYPE_INT_ARGB); WritableRaster refWR = ref.getRaster(); WritableRaster genWR = gen.getRaster(); WritableRaster dstWR = diff.getRaster(); boolean refPre = ref.isAlphaPremultiplied(); if (!refPre) { ColorModel cm = ref.getColorModel(); cm = GraphicsUtil.coerceData(refWR, cm, true); ref = new BufferedImage(cm, refWR, true, null); } boolean genPre = gen.isAlphaPremultiplied(); if (!genPre) { ColorModel cm = gen.getColorModel(); cm = GraphicsUtil.coerceData(genWR, cm, true); gen = new BufferedImage(cm, genWR, true, null); } int w = ref.getWidth(); int h = ref.getHeight(); int y, i, val; int[] refPix = null; int[] genPix = null; for (y = 0; y < h; y++) { refPix = refWR.getPixels(0, y, w, 1, refPix); genPix = genWR.getPixels(0, y, w, 1, genPix); for (i = 0; i < refPix.length; i++) { // val = ((genPix[i] - refPix[i]) * 5) + 128; val = ((refPix[i] - genPix[i]) * 10) + 128; if ((val & 0xFFFFFF00) != 0) { if ((val & 0x80000000) != 0) { val = 0; } else { val = 255; } } genPix[i] = val; } dstWR.setPixels(0, y, w, 1, genPix); } if (!genPre) { ColorModel cm = gen.getColorModel(); cm = GraphicsUtil.coerceData(genWR, cm, false); } if (!refPre) { ColorModel cm = ref.getColorModel(); cm = GraphicsUtil.coerceData(refWR, cm, false); } return diff; }
From source file:com.mikenimer.familydam.services.photos.ThumbnailService.java
/** * using the metadata orientation transformation information rotate the image. * @param image//from ww w .ja va2s . c o m * @param transform * @return * @throws Exception */ 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; }