/** * Creates a {@code BufferedImage} of the given size and type. If possible, * uses accelerated versions of BufferedImage from GraphicsConfiguration. * * @param pWidth the width of the image to create * @param pHeight the height of the image to create * @param pType the type of image to create (one of the constants from * {@link BufferedImage} or {@link #BI_TYPE_ANY}) * @param pTransparency the transparency type (from {@link Transparency}) * * @return a {@code BufferedImage} */ private static BufferedImage createBuffered(int pWidth, int pHeight, int pType, int pTransparency) { return createBuffered(pWidth, pHeight, pType, pTransparency, DEFAULT_CONFIGURATION); }
/** * Creates a transparent image. * * @see BufferedImage#BufferedImage(int,int,int) * * @param pWidth the requested width of the image * @param pHeight the requested height of the image * @param pType the type of {@code BufferedImage} to create * * @throws IllegalArgumentException if {@code pType} is not a valid type * for {@code BufferedImage} * * @return the new image */ public static BufferedImage createTransparent(int pWidth, int pHeight, int pType) { // Create BufferedImage image = createBuffered(pWidth, pHeight, pType, Transparency.TRANSLUCENT); // Clear image with transparent alpha by drawing a rectangle Graphics2D g = image.createGraphics(); try { g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, pWidth, pHeight); } finally { g.dispose(); } return image; }
static BufferedImage createClear(int pWidth, int pHeight, int pType, int pTransparency, Color pBackground, GraphicsConfiguration pConfiguration) { // Create int transparency = (pBackground != null) ? pBackground.getTransparency() : pTransparency; BufferedImage image = createBuffered(pWidth, pHeight, pType, transparency, pConfiguration); if (pBackground != null) { // Clear image with clear color, by drawing a rectangle Graphics2D g = image.createGraphics(); try { g.setComposite(AlphaComposite.Src); // Allow color to be translucent g.setColor(pBackground); g.fillRect(0, 0, pWidth, pHeight); } finally { g.dispose(); } } return image; }
BufferedImage image = createBuffered(pOriginal.getWidth(), pOriginal.getHeight(), pType, Transparency.TRANSLUCENT);
public BufferedImage filter(BufferedImage pSource, BufferedImage pDestination) { if (pSource == null) { throw new NullPointerException("source image is null"); } if (pSource == pDestination) { throw new IllegalArgumentException("source image cannot be the same as the destination image"); } int borderX = kernel.getWidth() / 2; int borderY = kernel.getHeight() / 2; BufferedImage original = addBorder(pSource, borderX, borderY); // Workaround for what seems to be a Java2D bug: // ConvolveOp needs explicit destination image type for some "uncommon" // image types. However, TYPE_3BYTE_BGR is what javax.imageio.ImageIO // normally returns for color JPEGs... :-/ BufferedImage destination = pDestination; if (original.getType() == BufferedImage.TYPE_3BYTE_BGR) { destination = ImageUtil.createBuffered( pSource.getWidth(), pSource.getHeight(), pSource.getType(), pSource.getColorModel().getTransparency(), null ); } // Do the filtering (if destination is null, a new image will be created) destination = convolve.filter(original, destination); if (pSource != original) { // Remove the border destination = destination.getSubimage(borderX, borderY, pSource.getWidth(), pSource.getHeight()); } return destination; }
image = createBuffered(getWidth(pOriginal), getHeight(pOriginal), pType, Transparency.TRANSLUCENT);//new BufferedImage(getWidth(pOriginal), getHeight(pOriginal), pType);
result = createBuffered( pOriginal.getWidth(), pOriginal.getHeight(), pOriginal.getType(), pOriginal.getColorModel().getTransparency()
/** * Creates a {@code BufferedImage} of the given size and type. If possible, * uses accelerated versions of BufferedImage from GraphicsConfiguration. * * @param pWidth the width of the image to create * @param pHeight the height of the image to create * @param pType the type of image to create (one of the constants from * {@link BufferedImage} or {@link #BI_TYPE_ANY}) * @param pTransparency the transparency type (from {@link Transparency}) * * @return a {@code BufferedImage} */ private static BufferedImage createBuffered(int pWidth, int pHeight, int pType, int pTransparency) { return createBuffered(pWidth, pHeight, pType, pTransparency, DEFAULT_CONFIGURATION); }
/** * Creates a {@code BufferedImage} of the given size and type. If possible, * uses accelerated versions of BufferedImage from GraphicsConfiguration. * * @param pWidth the width of the image to create * @param pHeight the height of the image to create * @param pType the type of image to create (one of the constants from * {@link BufferedImage} or {@link #BI_TYPE_ANY}) * @param pTransparency the transparency type (from {@link Transparency}) * * @return a {@code BufferedImage} */ private static BufferedImage createBuffered(int pWidth, int pHeight, int pType, int pTransparency) { return createBuffered(pWidth, pHeight, pType, pTransparency, DEFAULT_CONFIGURATION); }
/** * Creates a transparent image. * * @see BufferedImage#BufferedImage(int,int,int) * * @param pWidth the requested width of the image * @param pHeight the requested height of the image * @param pType the type of {@code BufferedImage} to create * * @throws IllegalArgumentException if {@code pType} is not a valid type * for {@code BufferedImage} * * @return the new image */ public static BufferedImage createTransparent(int pWidth, int pHeight, int pType) { // Create BufferedImage image = createBuffered(pWidth, pHeight, pType, Transparency.TRANSLUCENT); // Clear image with transparent alpha by drawing a rectangle Graphics2D g = image.createGraphics(); try { g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, pWidth, pHeight); } finally { g.dispose(); } return image; }
static BufferedImage createClear(int pWidth, int pHeight, int pType, int pTransparency, Color pBackground, GraphicsConfiguration pConfiguration) { // Create int transparency = (pBackground != null) ? pBackground.getTransparency() : pTransparency; BufferedImage image = createBuffered(pWidth, pHeight, pType, transparency, pConfiguration); if (pBackground != null) { // Clear image with clear color, by drawing a rectangle Graphics2D g = image.createGraphics(); try { g.setComposite(AlphaComposite.Src); // Allow color to be translucent g.setColor(pBackground); g.fillRect(0, 0, pWidth, pHeight); } finally { g.dispose(); } } return image; }
static BufferedImage createClear(int pWidth, int pHeight, int pType, int pTransparency, Color pBackground, GraphicsConfiguration pConfiguration) { // Create int transparency = (pBackground != null) ? pBackground.getTransparency() : pTransparency; BufferedImage image = createBuffered(pWidth, pHeight, pType, transparency, pConfiguration); if (pBackground != null) { // Clear image with clear color, by drawing a rectangle Graphics2D g = image.createGraphics(); try { g.setComposite(AlphaComposite.Src); // Allow color to be translucent g.setColor(pBackground); g.fillRect(0, 0, pWidth, pHeight); } finally { g.dispose(); } } return image; }
/** * Creates a transparent image. * * @see BufferedImage#BufferedImage(int,int,int) * * @param pWidth the requested width of the image * @param pHeight the requested height of the image * @param pType the type of {@code BufferedImage} to create * * @throws IllegalArgumentException if {@code pType} is not a valid type * for {@code BufferedImage} * * @return the new image */ public static BufferedImage createTransparent(int pWidth, int pHeight, int pType) { // Create BufferedImage image = createBuffered(pWidth, pHeight, pType, Transparency.TRANSLUCENT); // Clear image with transparent alpha by drawing a rectangle Graphics2D g = image.createGraphics(); try { g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, pWidth, pHeight); } finally { g.dispose(); } return image; }
BufferedImage image = createBuffered(pOriginal.getWidth(), pOriginal.getHeight(), pType, Transparency.TRANSLUCENT);
BufferedImage image = createBuffered(pOriginal.getWidth(), pOriginal.getHeight(), pType, Transparency.TRANSLUCENT);
public BufferedImage filter(BufferedImage pSource, BufferedImage pDestination) { if (pSource == null) { throw new NullPointerException("source image is null"); } if (pSource == pDestination) { throw new IllegalArgumentException("source image cannot be the same as the destination image"); } int borderX = mKernel.getWidth() / 2; int borderY = mKernel.getHeight() / 2; BufferedImage original = addBorder(pSource, borderX, borderY); // Workaround for what seems to be a Java2D bug: // ConvolveOp needs explicit destination image type for some "uncommon" // image types. However, TYPE_3BYTE_BGR is what javax.imageio.ImageIO // normally returns for color JPEGs... :-/ BufferedImage destination = pDestination; if (original.getType() == BufferedImage.TYPE_3BYTE_BGR) { destination = ImageUtil.createBuffered( pSource.getWidth(), pSource.getHeight(), pSource.getType(), pSource.getColorModel().getTransparency(), null ); } // Do the filtering (if destination is null, a new image will be created) destination = mConvolve.filter(original, destination); if (pSource != original) { // Remove the border destination = destination.getSubimage(borderX, borderY, pSource.getWidth(), pSource.getHeight()); } return destination; }
public BufferedImage filter(BufferedImage pSource, BufferedImage pDestination) { if (pSource == null) { throw new NullPointerException("source image is null"); } if (pSource == pDestination) { throw new IllegalArgumentException("source image cannot be the same as the destination image"); } int borderX = kernel.getWidth() / 2; int borderY = kernel.getHeight() / 2; BufferedImage original = addBorder(pSource, borderX, borderY); // Workaround for what seems to be a Java2D bug: // ConvolveOp needs explicit destination image type for some "uncommon" // image types. However, TYPE_3BYTE_BGR is what javax.imageio.ImageIO // normally returns for color JPEGs... :-/ BufferedImage destination = pDestination; if (original.getType() == BufferedImage.TYPE_3BYTE_BGR) { destination = ImageUtil.createBuffered( pSource.getWidth(), pSource.getHeight(), pSource.getType(), pSource.getColorModel().getTransparency(), null ); } // Do the filtering (if destination is null, a new image will be created) destination = convolve.filter(original, destination); if (pSource != original) { // Remove the border destination = destination.getSubimage(borderX, borderY, pSource.getWidth(), pSource.getHeight()); } return destination; }
image = createBuffered(getWidth(pOriginal), getHeight(pOriginal), pType, Transparency.TRANSLUCENT);//new BufferedImage(getWidth(pOriginal), getHeight(pOriginal), pType);
image = createBuffered(getWidth(pOriginal), getHeight(pOriginal), pType, Transparency.TRANSLUCENT);//new BufferedImage(getWidth(pOriginal), getHeight(pOriginal), pType);
result = createBuffered( pOriginal.getWidth(), pOriginal.getHeight(), pOriginal.getType(), pOriginal.getColorModel().getTransparency()