List of utility methods to do Image
int[] | absoluteDifferenceImage(int[] rgb1, int[] rgb2, double scale) Generate the absolute difference image between two images if (rgb1.length != rgb2.length) throw new RuntimeException("The two images need to have the same number of pixels"); int[] out = new int[rgb1.length]; for (int i = 0; i < rgb1.length; i++) { int c1 = rgb1[i]; int r1 = (c1 >> 16) & 0xff; int g1 = (c1 >> 8) & 0xff; int b1 = (c1) & 0xff; ... |
File | checkLosslessImageExt(Component parent, File f) Optionally validate the file name to have an extension of a lossless image format. if (f == null) return null; String ext = getExtension(f); if (ext == null) { Object[] options = { "Use .png", "No Extension" }; String msg = "<html><body><b>Are you sure to not use a file extension?</b><br><br>" + "An image file without a proper extension<br>may not be opened correctly by other programs.</body></html>"; int n = JOptionPane.showOptionDialog(parent, msg, "Save Image", JOptionPane.YES_NO_OPTION, ... |
void | configureMacOSApplication(String appName, String dockImagePath) Set common properties and dock image for the given application is we are running on Mac OS X configureMacOSApplication(appName); try { Class<?> clazz = Class.forName("com.apple.eawt.Application"); Method method = clazz.getMethod("getApplication", null); Object application = method.invoke(null, null); Method method2 = application.getClass().getMethod("setDockIconImage", Image.class); URL dockImageURL = "".getClass().getResource(dockImagePath); Image dockImage = new ImageIcon(dockImageURL).getImage(); ... |
BufferedImage | CreateCopy(Image srcImg) Create Copy return ScaleToSize(srcImg, -1, -1);
|
Cursor | createCursor(Image cursorImage, Point hotSpot, String name) create Cursor if (hotSpot == null) hotSpot = new Point(); Dimension prefDimension = Toolkit.getDefaultToolkit().getBestCursorSize(hotSpot.x, hotSpot.y); if (hotSpot.x > prefDimension.width - 1) hotSpot.x = prefDimension.width - 1; else if (hotSpot.x < 0) hotSpot.x = 0; if (hotSpot.y > prefDimension.height - 1) ... |
Cursor | createCursor(Image image, Point hotspot, String name) Creates a cursor from an image int w = image.getWidth(null); int h = image.getHeight(null); Dimension size = Toolkit.getDefaultToolkit().getBestCursorSize(w, h); if ((size.width != w) || (size.height != h)) { BufferedImage b = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = b.createGraphics(); g.drawImage(image, 0, 0, null); image = b; ... |
Image | createMemoryImage(int width, int height, Color colour, JComponent someComponent) Creates a square image of a particular colour. Image result; int[] pixels = new int[width * height]; int arraySize = 3; Color colorArray[] = new Color[arraySize]; for (int i = 0; i < arraySize; i++) { colorArray[i] = colour; byte reds[] = new byte[arraySize]; ... |
BufferedImage | createQualityResizedImage(Image orginalImage, int width, int height, boolean keepRatio) create Quality Resized Image return createQualityResizedImage(orginalImage, width, height, false, keepRatio, Color.WHITE, false);
|
BufferedImage | createScaledImage(Image inImage, int inWidth, int inHeight) Create a scaled and smoothed image according to the specified size Image smallerImage = inImage.getScaledInstance(inWidth, inHeight, Image.SCALE_SMOOTH); Image tempImage = new ImageIcon(smallerImage).getImage(); tempImage.getWidth(null); BufferedImage buffer = new BufferedImage(inWidth, inHeight, BufferedImage.TYPE_INT_RGB); Graphics buffG = buffer.getGraphics(); buffG.drawImage(smallerImage, 0, 0, inWidth, inHeight, null); buffG.dispose(); smallerImage = null; ... |
ImageIcon | createShadowPicture(Image buf) Creates an ImageIcon with a Shadow buf = removeTransparency(buf); BufferedImage splash; JLabel label = new JLabel(); int width = buf.getWidth(null); int height = buf.getHeight(null); int extra = 4; splash = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) splash.getGraphics(); ... |