List of utility methods to do Image
void | sizeToImage(JComponent component, Image image) Sizes a component based on the size of the provided image. if (image != null) { int height = image.getHeight(null); int width = image.getWidth(null); Dimension d = new Dimension(width, height); component.setPreferredSize(d); |
Image | swapColor(Image image, Color imageColor, Color newColor) swap Color final int irgb = imageColor.getRGB(); final int nrgb = newColor.getRGB(); RGBImageFilter filter = new RGBImageFilter() { @Override public int filterRGB(int x, int y, int rgb) { if (rgb == irgb) { return nrgb; return rgb; }; FilteredImageSource filteredSrc = new FilteredImageSource(image.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(filteredSrc); |
void | texturePaintHorizontal(JComponent parent, Graphics g, Image image, Rectangle areaToPaint) Paint a single texture horizontally across the screen. int imageWidth = image.getWidth(parent); int imageHeight = image.getHeight(parent); int cols = areaToPaint.width / imageWidth; for (int x = 0; x < cols; x++) { g.drawImage(image, x * imageWidth + areaToPaint.x, areaToPaint.y, parent); int remainingWidth = areaToPaint.width - cols * imageWidth; if (remainingWidth > 0) { ... |
boolean | usesAlpha(Image image) This method returns true if the specified image has at least one pixel that is not fully opaque. if (image == null) { return false; BufferedImage bimage = toBufferedImage(image); Raster alphaRaster = bimage.getAlphaRaster(); if (alphaRaster == null) { return false; DataBuffer dataBuffer = alphaRaster.getDataBuffer(); for (int i = 0; i < dataBuffer.getSize(); i++) { int alpha = dataBuffer.getElem(i); if (alpha < 255) { return true; return false; |
Boolean | verifyImageSizeBigger(byte[] imageData, int maxDim) verify Image Size Bigger ImageIcon imageIcon = new ImageIcon(imageData); Image inImage = imageIcon.getImage(); int origWidth = inImage.getWidth(null); int origHeight = inImage.getHeight(null); return ((origWidth > maxDim) && (origHeight > maxDim)); |