WritableRaster alphaRaster = source.getAlphaRaster(); if (alphaRaster == null || (!settings.stripWhitespaceX && !settings.stripWhitespaceY)) return new Rect(source, 0, 0, source.getWidth(), source.getHeight(), false);
WritableRaster alphaRaster = source.getAlphaRaster(); if (alphaRaster == null || (!settings.stripWhitespaceX && !settings.stripWhitespaceY)) return new Rect(source, 0, 0, source.getWidth(), source.getHeight(), false);
final int width = image.getWidth(); final int height = image.getHeight(); final boolean hasAlphaChannel = image.getAlphaRaster() != null;
private static BufferedImage getAlphaImage(BufferedImage image) throws IOException { if (!image.getColorModel().hasAlpha()) { return null; } if (image.getTransparency() == Transparency.BITMASK) { throw new UnsupportedOperationException("BITMASK Transparency JPEG compression is not" + " useful, use LosslessImageFactory instead"); } WritableRaster alphaRaster = image.getAlphaRaster(); if (alphaRaster == null) { // happens sometimes (PDFBOX-2654) despite colormodel claiming to have alpha return null; } BufferedImage alphaImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY); alphaImage.setData(alphaRaster); return alphaImage; }
private BufferedImage createMaskedImage() { BufferedImage masked = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = masked.createGraphics(); try { graphics.drawImage(image, 0, 0, null); } finally { graphics.dispose(); } WritableRaster alphaRaster = masked.getAlphaRaster(); byte[] trans = {0x0}; for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < getWidth(); x++) { if (mask.isTransparent(x, y)) { alphaRaster.setDataElements(x, y, trans); } } } return masked; } }
if (COSName.ALPHA.equals(softMask.getSubType())) gray.setData(image.getAlphaRaster());
image.getAlphaRaster().setRect(mask); image.getAlphaRaster().setRect(mask); Arrays.fill(solid, (byte) -1); WritableRaster mask = Raster.createBandedRaster(new DataBufferByte(solid, solid.length), width, height, width, new int[]{0}, new int[]{0}, null); image.getAlphaRaster().setRect(mask);
BufferedImage image = ImageIO.read(new File(name)); int[] alpha = new int[1]; //containg alpha-value for one pixel. image.getAlphaRaster().getPixel(x, y, alpha); System.out.println(alpha[0]); //gives the alpha value for x,y
private GraphBuffer(BufferedImage image){ this.image = image; width = image.getWidth(); height = image.getHeight(); pixels = ((DataBufferByte)this.image.getRaster().getDataBuffer()).getData(); hasAlphaChannel = image.getAlphaRaster() != null; g = image.createGraphics(); }
public static BufferedImage applyAlphaMask(BufferedImage src, BufferedImage mask) { WritableRaster alpha = mask.getAlphaRaster(); int[] data = new int[mask.getWidth() * mask.getHeight()]; alpha.getPixels(0, 0, mask.getWidth(), mask.getHeight(), data); if (src.getAlphaRaster() == null) { BufferedImage t = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); t.getGraphics().drawImage(src, 0, 0, null); src = t; } src.getAlphaRaster().setPixels(0, 0, mask.getWidth(), mask.getHeight(), data); return src; }
public static BufferedImage applyAlphaMask(BufferedImage src, BufferedImage mask) { WritableRaster alpha = mask.getAlphaRaster(); int[] data = new int[mask.getWidth() * mask.getHeight()]; alpha.getPixels(0, 0, mask.getWidth(), mask.getHeight(), data); if (src.getAlphaRaster() == null) { BufferedImage t = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); t.getGraphics().drawImage(src, 0, 0, null); src = t; } src.getAlphaRaster().setPixels(0, 0, mask.getWidth(), mask.getHeight(), data); return src; }
protected Raster toRaster(Component c, Icon mask) { Raster raster = null; if (mask != null) { Rectangle bounds = new Rectangle(0, 0, mask.getIconWidth(), mask.getIconHeight()); BufferedImage clip = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = clip.createGraphics(); g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, bounds.width, bounds.height); g.setComposite(AlphaComposite.SrcOver); mask.paintIcon(c, g, 0, 0); raster = clip.getAlphaRaster(); } return raster; }
public void setBackground(BufferedImage image, Color color) { DataBuffer ar = image.getAlphaRaster().getDataBuffer(); int col = ((int) color.getAlpha() << 24) + ((int) color.getRed() << 16) + ((int) color.getGreen() << 8) + ((int) color.getBlue()); for (int i = 0; i < width * height; i++) { ar.setElem(i, col); } } final private Matrix4 HALF = Matrix4.translation(0.5f, 0f, 0f);
protected Raster toRaster(Component c, Icon mask) { Raster raster = null; if (mask != null) { Rectangle bounds = new Rectangle(0, 0, mask.getIconWidth(), mask.getIconHeight()); BufferedImage clip = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = clip.createGraphics(); g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, bounds.width, bounds.height); g.setComposite(AlphaComposite.SrcOver); mask.paintIcon(c, g, 0, 0); raster = clip.getAlphaRaster(); } return raster; }
public static BufferedImage applyMask(BufferedImage src, BufferedImage mask) { if (src.getAlphaRaster() == null) { BufferedImage t = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); t.getGraphics().drawImage(src, 0, 0, null); src = t; } int w = Math.min(src.getWidth(), mask.getWidth()); int h = Math.min(src.getHeight(), mask.getHeight()); int[] data = mask.getRGB(0, 0, w, h, null, 0, w); for (int i = 0; i < data.length; i++) { data[i] = red(data[i]); } src.getAlphaRaster().setPixels(0, 0, w, h, data); return src; }
public static BufferedImage applyMask(BufferedImage src, BufferedImage mask) { if (src.getAlphaRaster() == null) { BufferedImage t = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); t.getGraphics().drawImage(src, 0, 0, null); src = t; } int w = Math.min(src.getWidth(), mask.getWidth()); int h = Math.min(src.getHeight(), mask.getHeight()); int[] data = mask.getRGB(0, 0, w, h, null, 0, w); for (int i = 0; i < data.length; i++) { data[i] = red(data[i]); } src.getAlphaRaster().setPixels(0, 0, w, h, data); return src; }
/** * Returns <code>true</code> if the provided image has any kind of transparent areas */ public static boolean hasTransparency(BufferedImage image) { final Raster alphaRaster = image.getAlphaRaster(); if (image.getTransparency() != Transparency.TRANSLUCENT || alphaRaster == null) { return false; } int [] pixels = alphaRaster.getPixels(0, 0, alphaRaster.getWidth(), alphaRaster .getHeight(), (int []) null); for (int i : pixels) { if (i != 255) { return true; } } return false; }
public ImageDataStream(BufferedImage image, Interleaving interleaving) { this.image = image; this.interleaving = interleaving; width = image.getWidth(); height = image.getHeight(); x = -1; y = 0; Raster alphaRaster = image.getAlphaRaster(); if (interleaving == Interleaving.ALPHA_ONLY) { raster = alphaRaster; } else { raster = image.getRaster(); } opaque = alphaRaster == null; byteBuffer = new LinkedList<>(); sampleValues = new int[raster.getNumBands()]; sampleSizes = raster.getSampleModel().getSampleSize(); }
public BufferedImage getSnapshot() { if (snapshot == null) { snapshot = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(getWidth(), getHeight()); if (log) { PropUtils.log(ButtonPanel.class, "Created " + snapshot + " custom editor button backing image"); } if (snapshot.getAlphaRaster() == null) { //Alpha not supported, could cause corruption (issue //39280) - use a bufferedImage which will support alpha, //although less efficient to blit snapshot = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); } Graphics g = snapshot.getGraphics(); super.paint(g); } return snapshot; } }
protected BufferedImage makeImage( final ImageProcessor ip, final FloatProcessor mask ) { final BufferedImage transformedImage = new BufferedImage( ip.getWidth(), ip.getHeight(), null == mask ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB ); final Image img = ip.createImage(); transformedImage.createGraphics().drawImage( img, 0, 0, null ); img.flush(); if (null != mask) { transformedImage.getAlphaRaster().setPixels( 0, 0, ip.getWidth(), ip.getHeight(), ( float[] )mask.getPixels() ); } return transformedImage; }