本文整理了Java中java.awt.image.BufferedImage.getTransparency()
方法的一些代码示例,展示了BufferedImage.getTransparency()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedImage.getTransparency()
方法的具体详情如下:
包路径:java.awt.image.BufferedImage
类名称:BufferedImage
方法名:getTransparency
暂无
代码示例来源:origin: stackoverflow.com
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;
}
代码示例来源:origin: rkalla/imgscalr
width,
height,
(src.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB
: BufferedImage.TYPE_INT_ARGB));
代码示例来源:origin: rkalla/imgscalr
int type = (src.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB
: BufferedImage.TYPE_INT_ARGB);
BufferedImage result = new BufferedImage(src.getWidth(),
代码示例来源:origin: stackoverflow.com
boolean higherQuality)
int type = (img.getTransparency() == Transparency.OPAQUE) ?
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage ret = (BufferedImage)img;
代码示例来源:origin: shopizer-ecommerce/shopizer
int targetWidth, int targetHeight, Object hint,
boolean higherQuality) {
int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
: BufferedImage.TYPE_INT_ARGB;
BufferedImage ret = (BufferedImage) img;
代码示例来源:origin: plantuml/plantuml
final int targetWidth = targetDim.width;
final int targetHeight = targetDim.height;
final int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
: BufferedImage.TYPE_INT_ARGB;
BufferedImage ret = (BufferedImage) img;
代码示例来源:origin: apache/nifi
if(image.getTransparency() == Transparency.OPAQUE) {
imageType = BufferedImage.TYPE_INT_RGB;
代码示例来源:origin: rkalla/imgscalr
boolean imageHasAlpha = (src.getTransparency() != BufferedImage.OPAQUE);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
if (img.getTransparency() == Transparency.OPAQUE){
ByteBuffer data = BufferUtils.createByteBuffer(img.getWidth()*img.getHeight()*3);
代码示例来源:origin: haraldk/TwelveMonkeys
private static int getTransparency(Image pImage) {
if (pImage instanceof BufferedImage) {
BufferedImage bi = (BufferedImage) pImage;
return bi.getTransparency();
}
return Transparency.OPAQUE;
}
代码示例来源:origin: stackoverflow.com
BufferedImage image = ImageIO.read ( url );
BufferedImage convertedImage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment ();
GraphicsDevice gd = ge.getDefaultScreenDevice ();
GraphicsConfiguration gc = gd.getDefaultConfiguration ();
convertedImage = gc.createCompatibleImage (image.getWidth (),
image.getHeight (),
image.getTransparency () );
Graphics2D g2d = convertedImage.createGraphics ();
g2d.drawImage ( image, 0, 0, image.getWidth (), image.getHeight (), null );
g2d.dispose()
代码示例来源:origin: nguyenq/tess4j
/**
* Convenience method that returns a scaled instance of the provided
* {@code BufferedImage}.
*
* @param image the original image to be scaled
* @param targetWidth the desired width of the scaled instance, in pixels
* @param targetHeight the desired height of the scaled instance, in pixels
* @return a scaled version of the original {@code BufferedImage}
*/
public static BufferedImage getScaledInstance(BufferedImage image, int targetWidth, int targetHeight) {
int type = (image.getTransparency() == Transparency.OPAQUE)
? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage tmp = new BufferedImage(targetWidth, targetHeight, type);
Graphics2D g2 = tmp.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2.drawImage(image, 0, 0, targetWidth, targetHeight, null);
g2.dispose();
return tmp;
}
代码示例来源:origin: nguyenq/tess4j
/**
* A replacement for the standard <code>BufferedImage.getSubimage</code>
* method.
*
* @param image
* @param x the X coordinate of the upper-left corner of the specified
* rectangular region
* @param y the Y coordinate of the upper-left corner of the specified
* rectangular region
* @param width the width of the specified rectangular region
* @param height the height of the specified rectangular region
* @return a BufferedImage that is the subimage of <code>image</code>.
*/
public static BufferedImage getSubImage(BufferedImage image, int x, int y, int width, int height) {
int type = (image.getTransparency() == Transparency.OPAQUE)
? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage tmp = new BufferedImage(width, height, type);
Graphics2D g2 = tmp.createGraphics();
g2.drawImage(image.getSubimage(x, y, width, height), 0, 0, null);
g2.dispose();
return tmp;
}
代码示例来源:origin: apache/pdfbox
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;
}
代码示例来源:origin: apache/pdfbox
int alphaByteIdx = 0;
int alphaBitPos = 7;
int transparency = image.getTransparency();
int apbc = transparency == Transparency.BITMASK ? 1 : 8;
byte[] alphaImageData;
代码示例来源:origin: haraldk/TwelveMonkeys
BufferedImage buffered = (BufferedImage) pImage;
if (buffered.getType() != BufferedImage.TYPE_CUSTOM && equals(buffered.getColorModel(), pConfiguration.getColorModel(buffered.getTransparency()))) {
return buffered;
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testGetBufferedImageGIF() {
URL resource = getClass().getResource("/tux.gif");
assertNotNull(resource);
Image source = Toolkit.getDefaultToolkit().createImage(resource);
assertNotNull(source);
BufferedImageFactory factory = new BufferedImageFactory(source);
BufferedImage image = factory.getBufferedImage();
assertEquals(250, image.getWidth());
assertEquals(250, image.getHeight());
assertEquals(Transparency.BITMASK, image.getTransparency());
// All corners of image should be fully transparent
assertEquals(0, image.getRGB(0, 0) >>> 24);
assertEquals(0, image.getRGB(249, 0) >>> 24);
assertEquals(0, image.getRGB(0, 249) >>> 24);
assertEquals(0, image.getRGB(249, 249) >>> 24);
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testMultiChannelNoTransparencyPSB() throws IOException {
PSDImageReader imageReader = createReader();
// The following PSB is RGB, has 4 channels (1 alpha/auxillary channel), but should be treated as opaque
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource("/psb/rgb-multichannel-no-transparency.psb"))) {
imageReader.setInput(stream);
BufferedImage image = imageReader.read(0);
assertEquals(Transparency.OPAQUE, image.getTransparency());
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testMultiChannelNoTransparencyPSD() throws IOException {
PSDImageReader imageReader = createReader();
// The following PSD is RGB, has 4 channels (1 alpha/auxillary channel), but should be treated as opaque
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource("/psd/rgb-multichannel-no-transparency.psd"))) {
imageReader.setInput(stream);
BufferedImage image = imageReader.read(0);
assertEquals(Transparency.OPAQUE, image.getTransparency());
}
}
代码示例来源:origin: apache/pdfbox
imageXObject.getCOSObject().setItem(COSName.DECODE_PARMS, decodeParms);
if (image.getTransparency() != Transparency.OPAQUE)
内容来源于网络,如有侵权,请联系作者删除!