bufferedimage

Paint a JPanel to a BufferedImage or Print it without rendering it to screen first

微笑、不失礼 提交于 2019-12-24 07:48:15
问题 Picture this... A program GUI JFrame that is split in 2, EAST and WEST. The first JPanel is just a print preview screen. The EAST side of the JFrame is where the user can create a 1 2 or 3 size image. The user clicks the "Add" button and the defined image on the right goes to the panel on the left. So if the user clicks "Add" 3 times with different size images, then the panel uses FlowLayout to organize the added panel images added on the left. When you run this code, you can see a sorta idea

How to prevent loss of image quality while using ImageIO.write() method?

寵の児 提交于 2019-12-24 04:31:47
问题 I am dealing with Images in java where I do read and write Images in my local disk. My Problem is while writing Images I am losing the quality of the actual Image I read. It reduces the quality by image file size from 6.19MB(actual image size) file to 1.22MB(written using ImageIO.write() which is drastic loss. How can I prevent this loss when i do use ImageIO.write(image, "jpg", os); for writing Image. Remember, I dont need any compression over here. Just I want to read the Image and write

What exactly does getSubimage() of BufferedImage do?

ぃ、小莉子 提交于 2019-12-24 04:26:06
问题 I'm working on a 'drawing' application. The entire 'drawing' is constantly stored in a BufferedImage object (using a constant update loop). Let's call it drawingArea . I'm implementing a selection tool, using the BufferedImage class' getSubimage() method. The user uses this tool to select an area of the drawing, and paste it anywhere on the drawing. The user selects an area by dragging the mouse, and when he/she releases the mouse, the selected area is stored in a BufferedImage . This is done

how to create a gray scale image from pixel values using java

感情迁移 提交于 2019-12-24 03:06:08
问题 My requirement is that, I need to convert a color image into gray scale image and obtain pixels values of gray scale image to an array and perform some encryption algorithm on that array and again using this changed pixel array, I need to convert back/create a gray scale image and display it. Here are my doubts. Using the color image I have obtained the RGB pixel values in three different arrays. As per my knowledge, gray scale pixels can be obtained by doing red+green+blue/3=gray . Here red,

android equivalent code for graphics2D

寵の児 提交于 2019-12-24 02:23:51
问题 I have been trying to get an android equivalent code for the following :- private BufferedImage user_space(BufferedImage image) { BufferedImage new_img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = new_img.createGraphics(); graphics.drawRenderedImage(image, null); graphics.dispose(); return new_img; } I want an android equivalent of Graphics2D. I have been searching for a while and found out that Canvas in android can do some

android equivalent code for graphics2D

断了今生、忘了曾经 提交于 2019-12-24 02:23:08
问题 I have been trying to get an android equivalent code for the following :- private BufferedImage user_space(BufferedImage image) { BufferedImage new_img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = new_img.createGraphics(); graphics.drawRenderedImage(image, null); graphics.dispose(); return new_img; } I want an android equivalent of Graphics2D. I have been searching for a while and found out that Canvas in android can do some

How to pass image from Applet to JSF backing bean

╄→гoц情女王★ 提交于 2019-12-24 00:35:22
问题 I am working with a web application in which there is a Java Applet that captures an image from a wacom device into a RenderedImage object. The applet itself is embedded into a JSF 2.0 page. I need to pass the created RenderedImage from Applet to a JSF backing bean so that it would be a part of a User object. My backing bean is view scoped. I'm really lost with this. I've been searching for a good example on how this goal can be achieved. Should I use JSObject , or should I send an image to a

Converting BufferedImage to ByteBuffer

强颜欢笑 提交于 2019-12-23 16:19:45
问题 I'm trying to convert a Buffered image into a ByteBuffer but i get this exception java.awt.image.DataBufferInt cannot be cast to java.awt.image.DataBufferByte can someone please help me out and suggest a good method of conversion. Source: public static ByteBuffer convertImageData(BufferedImage bi) { byte[] pixelData = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData(); // return ByteBuffer.wrap(pixelData); ByteBuffer buf = ByteBuffer.allocateDirect(pixelData.length); buf.order

BufferedImage bytes have a different byte order, when running from Eclipse and the command line

老子叫甜甜 提交于 2019-12-23 13:14:04
问题 I was trying to convert a BufferedImage 's byte[] from 32-bit RGBA to 24-bit RGB. According to this answer the fastest way to get the byte[] from the image is: byte[] pixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData(); So I iterate over all bytes assuming their order is R G B A and for every 4 bytes, I write the first 3 in an output byte[] (i.e. ignoring the alpha value). This works fine when run from Eclipse and the bytes are converted correctly. However when I

Using several bufferedImages in java

∥☆過路亽.° 提交于 2019-12-23 10:55:04
问题 I'm making a game in a java applet and I'm trying to optimise my code to reduce flickering. I've already implemented double buffering, so I'm trying to use another BufferedImage in order to store a picture of the elements of the game's background that don't change. Here's the relevant portion of my code... public class QuizApplet extends Applet { //The image I'm trying to use to store components of the game's gui that don't change within a game private BufferedImage QBuffImg = new