List of utility methods to do BufferedImage Create
BufferedImage | convertToBufferedImage(BufferedImage image, int imageType) Converts an image to a buffered image with specified color model/format. BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), imageType); Graphics2D g2 = result.createGraphics(); g2.drawImage(image, null, 0, 0); return result; |
BufferedImage | getBufferedImage(byte[] imgStr) get Buffered Image return ImageIO.read(new java.io.ByteArrayInputStream(imgStr)); |
void | getBufferedImage(Component comp, BufferedImage image) Mendapatkan BufferedImage dari sebuah komponen Graphics2D g2 = image.createGraphics(); comp.paint(g2); g2.dispose(); |
BufferedImage | getBufferedImage(File file) get Buffered Image try { return ImageIO.read(file); } catch (IOException e) { e.printStackTrace(); return null; |
BufferedImage | getBufferedImage(String imageFile, Component c) Creates a BufferedImage from the given image file.
if (imageFile == null || c == null) { return null; BufferedImage bufferedImage = (BufferedImage) imageCache.get(imageFile); if (bufferedImage != null) { return bufferedImage; Image image = c.getToolkit().getImage(imageFile); ... |
BufferedImage | getBufferedImage(String imagePath) get Buffered Image return getBufferedImage(imagePath, false, 0, 1 * 1000);
|
BufferedImage | getBufferedImageAsType(int type, BufferedImage image, int sizeX, int sizeY) get Buffered Image As Type if (image.getType() == type) { return image; } else { BufferedImage result = new BufferedImage(sizeX, sizeY, type); Graphics g = result.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return result; ... |
byte[] | getBufferedImageBytes(BufferedImage bufferedImage) get Buffered Image Bytes if (bufferedImage == null) { throw new IllegalArgumentException("Input the BufferedImage is null."); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] bytes = null; try { ImageIO.write(bufferedImage, "png", out); out.flush(); ... |
BufferedImage | getBufferedImaged(Image img, int width, int height) This method is used for converting a java.awt.image.Image to scaled BufferedImage of desired width and height. Image image = img.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage bufferedImg = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); bufferedImg.getGraphics().drawImage(image, 0, 0, null); return bufferedImg; |
BufferedImage | getBufferedImageFrom3bytePixelArray(int[] rgb, int width, int height) Converts an integer array with Red, Green and Blue values of each pixel, sequentially, to a BufferedImage BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); image.setRGB(0, 0, width, height, rgb, 0, width); for (int i = 0; i < image.getWidth(); i++) { for (int j = 0; j < image.getHeight(); j++) { int[] c; c = image.getRaster().getPixel(i, j, new int[4]); if (c[0] != c[1] || c[0] != c[2] || c[1] != c[2]) { System.out.println(c[0] + " " + c[1] + " " + c[2]); ... |