bufferedimage

Java BufferedImage JPG compression without writing to file

邮差的信 提交于 2019-12-02 02:11:19
I've seen several examples of making compressed JPG images from Java BufferedImage objects by writing to file, but is it possible to perform JPG compression without writing to file? Perhaps by writing to a ByteArrayOutputStream like this ? ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next(); ImageWriteParam jpgWriteParam = jpgWriter.getDefaultWriteParam(); jpgWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpgWriteParam.setCompressionQuality(0.7f); ImageOutputStream outputStream = createOutputStream(); jpgWriter.setOutput(outputStream); IIOImage outputImage

When creating a BufferedImage from a JPanel (w/o a JFrame), can I also use a layout manager?

僤鯓⒐⒋嵵緔 提交于 2019-12-02 00:49:57
I am trying to create a BufferedImage from a JPanel, without using a JFrame. Yesterday, I was finally able to get the image to appear with help from this community (see below), but now I'm having some layout trouble. All of the components on the BufferedImage begin drawing at 0,0, instead of following the layout manager. Does anyone know of a solution for this problem? Yesterday's question: Can I create a BufferedImage from a JPanel without rendering in a JFrame? In the code below, the two labels will overwrite each other in the top left corner of the image. import java.awt.Color; import java

How can I save a BufferedImage to be below a particular size

这一生的挚爱 提交于 2019-12-01 17:02:25
问题 (Using java 8) Given a image user needs to be able to specify min/max image size in pixels and also maximum size of saved image in kbs, image is saved as jpg. So I have the first bit working, by resizing buffered image: public static BufferedImage resizeUsingImageIO(Image srcImage, int size) { int w = srcImage.getWidth(null); int h = srcImage.getHeight(null); // Determine the scaling required to get desired result. float scaleW = (float) size / (float) w; float scaleH = (float) size / (float)

How to fill the surface of the JButton completely with an ImageIcon?

主宰稳场 提交于 2019-12-01 10:44:09
Ive tried to fill the "surface" of the Jbutton completely with an ImageIcon. My result so far is: As you can see there is still some space between the edge of the "Exit"-Label and the edge of the button. You can see the button with the white-blue filling at the background. What I want is to cover this button COMPLETELY with the label. Is there a way to do that? Here is my code: package footballQuestioner; import java.awt.AlphaComposite; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Graphics2D;

How to display buffered image in JSF without writing image on disk?

巧了我就是萌 提交于 2019-12-01 09:32:01
I have a buffered image and I need to display it in a JSF page. Is there any UI component available which can display a buffered image directly? I am using JSF 2.2. If you only have the buffered image, you could use the Omnifaces library to which allows you to render images by passing a byte[] to the component <o:graphicImage value="#{bean.image}" dataURI="true" /> If you have the buffered image you could convert to byte array like so: ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write([image],[image_extension], baos); byte[] imageToPassAsValueAttr = baos.toByteArray();

How to fill the surface of the JButton completely with an ImageIcon?

柔情痞子 提交于 2019-12-01 09:03:10
问题 Ive tried to fill the "surface" of the Jbutton completely with an ImageIcon. My result so far is: As you can see there is still some space between the edge of the "Exit"-Label and the edge of the button. You can see the button with the white-blue filling at the background. What I want is to cover this button COMPLETELY with the label. Is there a way to do that? Here is my code: package footballQuestioner; import java.awt.AlphaComposite; import java.awt.BorderLayout; import java.awt.Color;

How to display buffered image in JSF without writing image on disk?

ε祈祈猫儿з 提交于 2019-12-01 07:51:40
问题 I have a buffered image and I need to display it in a JSF page. Is there any UI component available which can display a buffered image directly? I am using JSF 2.2. 回答1: If you only have the buffered image, you could use the Omnifaces library to which allows you to render images by passing a byte[] to the component <o:graphicImage value="#{bean.image}" dataURI="true" /> If you have the buffered image you could convert to byte array like so: ByteArrayOutputStream baos = new

Getting Greyscale pixel value from RGB colourspace in Java using BufferedImage

时光怂恿深爱的人放手 提交于 2019-12-01 06:45:20
Anyone know of a simple way of converting the RGBint value returned from <BufferedImage> getRGB(i,j) into a greyscale value? I was going to simply average the RGB values by breaking them up using this; int alpha = (pixel >> 24) & 0xff; int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel) & 0xff; and then average red,green,blue. But i feel like for such a simple operation I must be missing something... After a great answer to a different question, I should clear up what i want. I want to take the RGB value returned from getRGB(i,j), and turn that into a white

JFrame to image without showing the JFrame

我的梦境 提交于 2019-12-01 06:18:06
I am trying to render a JFrame to an image without ever displaying the JFrame itself (similar to what this question is asking). I have tried using this piece of code: private static BufferedImage getScreenShot(Component component) { BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB); // call the Component's paint method, using // the Graphics object of the image. component.paint(image.getGraphics()); return image; } However, this only works when the JFrame 's setVisible(true) is set. This will cause the image to be displayed on the

JFrame to image without showing the JFrame

心不动则不痛 提交于 2019-12-01 06:03:15
问题 I am trying to render a JFrame to an image without ever displaying the JFrame itself (similar to what this question is asking). I have tried using this piece of code: private static BufferedImage getScreenShot(Component component) { BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB); // call the Component's paint method, using // the Graphics object of the image. component.paint(image.getGraphics()); return image; } However, this