Questions tagged [bufferedimage]

The Java class BufferedImage is used to read and manipulate images and assist in double-buffering in desktop GUI applications.

The java.awt.image.BufferedImage Java class is part of the Abstract Windowing Toolkit group of classes that form part of the standard JDK.

The BufferedImage class contains methods to manipulate pixel values and is also used for double-buffering in applications that have a Java Swing GUI.

2150 questions
5
votes
1 answer

Unwanted black borders when trying to expand image to full size

When taking a screenshot of my scene in JavaFx, I save the BufferedImage to a file as a PNG/JPG. When I try to maximize the image size to its full length, I get Black borders on the picture from the left of the image to the bottom without the image…
Morelka
  • 177
  • 4
  • 16
5
votes
2 answers

JComponents not showing up with picture background?

My components are not showing up. How do I fix this? Code: import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import…
5
votes
2 answers

BufferedImage not displaying (all black) but Image can be displayed

I'm new to Java graphics (computer graphics in general) and Stack Overflow, so please help me out and help me phrase my problem better. At the moment, I'm trying to display a BufferedImage alongside the original image in a Java GUI. This is my…
Jacob Wang
  • 75
  • 1
  • 7
5
votes
3 answers

Java - Get an Image of a JPanel

I am writing a program in which I paint on a JPanel. How do I get an Image of the JPanel which is painted on it? I tried this code but all I get is a blank image with the Background color of my JPanel. The BufferedImage does not contain what is…
Christos Baziotis
  • 5,845
  • 16
  • 59
  • 80
5
votes
2 answers

Get buffered image from byte array of raw data

I am using JNA. and i am getting byte array of raw data from my c++ method. Now i am stuck how to get buffered image in java using this raw data byte array. I had tried few things to get it as tiff image but i dint get success. this are the code i…
Jony
  • 1,035
  • 7
  • 17
  • 43
5
votes
1 answer

How to change the contrast and brightness of an image stored as pixel values

I have an image that is stored as an array of pixel values. I want to be able to apply a brightness or contrast filter to this image. Is there any simple way, or algorithm, that I can use to achieve this. Here is my code... PlanarImage…
Jay
  • 1,235
  • 10
  • 28
  • 49
4
votes
4 answers

Trying to paint image to JFrame with Java BufferedImage, Graphics

I'm trying to capture the screen and then paint the image to a JFrame recursively while scaling the image (to create that effect you get when you look at a mirror in a mirror). I'm having trouble with my code - it doesn't paint any graphics. What am…
Ozzy
  • 8,244
  • 7
  • 55
  • 95
4
votes
1 answer

Java BufferedImage to clipboard gives IIOException

I'm trying to copy a image (held in a BufferedImage object) to the clipboard. I'm using the code from this answer. When trying to paste the image in a program, simply nothing happens. GIMP shows a message saying no image data was found in the…
Mira Weller
  • 2,406
  • 22
  • 27
4
votes
1 answer

Guidance on the BufferedImage.getSubimage(int x, int y, int w, int h) method?

I'm currently attempting to split an image, and I ran into a snitch and I have no idea why it's happening. Here's a quick pseudo code breakdown of my function Read in the image using the ImageIO.read(File file) method Split the images up using the…
imicrothinking
  • 95
  • 4
  • 11
4
votes
2 answers

How to convert BufferedImage which has a ComponentColorModel to SWT ImageData?

This SWT snippet converts a BufferedImage to SWT ImageData: static ImageData convertToSWT(BufferedImage bufferedImage) { if (bufferedImage.getColorModel() instanceof DirectColorModel) { ... } else if (bufferedImage.getColorModel()…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
4
votes
4 answers

How to Combine Images without loading them into RAM in Java

I have a very large (around a gigapixel) image I am trying to generate, and so far I can only create images up to around 40 megapixels in a BufferedImage before I get an out of memory error. I want to construct the image piece by piece, then combine…
Fractaly
  • 834
  • 2
  • 10
  • 25
4
votes
0 answers

How can I encode an image into AVIF using Java?

How can I encode an image into AVIF using Java? For someone with little proficiency in C, is it an uphill battle (and the only way) to do it with libavif via JNI? https://github.com/AOMediaCodec/libavif
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
4
votes
2 answers

Is accessing BufferedImage thread safe

In Java, I have 2 threads that are both accessing (not modifying) the same BufferedImage. I'm simply drawing the buffered image into a separate Graphics2D objects with code like this. Graphics2D g = getGraphics(); g.drawImage(myImage, 0, 0,…
awinbra
  • 694
  • 1
  • 7
  • 19
4
votes
1 answer

Why is my BufferedImage different when drawn to canvas?

Original https://drive.google.com/file/d/1B3xxfWkGsMs2_MQ_bUQ8_ALYI0DL-LIo/view?usp=sharing When saved to file https://drive.google.com/file/d/1z5euXupeHmiFebch4A39fVqGukoUiK0p/view?usp=sharing When printed to…
4
votes
1 answer

Java exception "Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to [I" when calling java.awt.image.BufferedImage.copyData()

In the following code, I'm trying to combine some 1024*1024 png into several larger pngs. The code fails with this exception: Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to [I at…
Mloc
  • 115
  • 1
  • 9