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
175
votes
6 answers

How to save a BufferedImage as a File

I am using the imgscalr Java library to resize an image . The result of a resize() method call is a BufferedImage object. I now want to save this as a file (usually .jpg). How can I do that? I want to go from BufferedImage -> File but perhaps this…
Ankur
  • 50,282
  • 110
  • 242
  • 312
139
votes
7 answers

Java - get pixel array from image

I'm looking for the fastest way to get pixel data (int the form int[][]) from a BufferedImage. My goal is to be able to address pixel (x, y) from the image using int[x][y]. All the methods I have found do not do this (most of them return int[]s).
ryyst
  • 9,563
  • 18
  • 70
  • 97
137
votes
9 answers

How do you clone a BufferedImage

I have an object which has many bufferedimages in it, I want to create a new object copying all the bufferedimages into the new object, but these new images may be altered and i don't want the original object images to be altered by altering the new…
f1wade
  • 2,877
  • 6
  • 27
  • 43
95
votes
4 answers

Java converting Image to BufferedImage

There is already question like this link on StackOverflow and the accepted answer is "casting": Image image = ImageIO.read(new File(file)); BufferedImage buffered = (BufferedImage) image; In my program I try: final float FACTOR = 4f; BufferedImage…
Arek Wilk
  • 1,062
  • 1
  • 9
  • 12
76
votes
2 answers

Java: BufferedImage to byte array and back

I see that a number of people have had a similar problem, however I'm yet to try find exactly what I'm looking for. So, I have a method which reads an input image and converts it to a byte array: File imgPath = new File(ImageName); …
user1875290
  • 909
  • 1
  • 7
  • 8
69
votes
7 answers

Java - resize image without losing quality

I have 10,000 photos that need to be resized so I have a Java program to do that. Unfortunately, the quality of the image is poorly lost and I don't have access to the uncompressed images. import java.awt.Graphics; import…
user3362954
  • 1,221
  • 2
  • 15
  • 23
58
votes
7 answers

How to scale a BufferedImage

Following the javadocs, I have tried to scale a BufferedImage without success here is my code: BufferedImage image = MatrixToImageWriter.getBufferedImage(encoded); Graphics2D grph = image.createGraphics(); grph.scale(2.0, 2.0); grph.dispose(); I…
Thiago Diniz
  • 3,041
  • 5
  • 30
  • 35
55
votes
7 answers

Bufferedimage resize

I am trying to resized a bufferedimage. I am able to store it and show up on a jframe no problems but I can't seem to resize it. Any tips on how I can change this to make it work and show the image as a 200*200 file would be great private void…
user1060187
  • 957
  • 5
  • 12
  • 28
55
votes
5 answers

Convert RGB values to Integer

So in a BufferedImage, you receive a single integer that has the RGB values represented in it. So far I use the following to get the RGB values from it: // rgbs is an array of integers, every single integer represents the // RGB values combined in…
Rahat Ahmed
  • 2,191
  • 2
  • 30
  • 40
51
votes
4 answers

Java BufferedImage getting red, green and blue individually

The getRGB() method returns a single int. How can I get individually the red, green and blue colors all as the values between 0 and 255?
deltanovember
  • 42,611
  • 64
  • 162
  • 244
50
votes
5 answers

Understanding BufferedImage.getRGB output values

I'm getting an integer value for the pixel in an image using this method: int colour = img.getRGB(x, y); Then I'm printing out the values and I see that black pixels correspond to a value like "-16777216", a kind of blue to something like…
leonardo
  • 537
  • 1
  • 4
  • 7
47
votes
5 answers

What does "& 0xff" do?

I am trying to understand the code below where b is a given integer and image is an image. I understand that if the RGB value at given point i,j is greater than b then set that pixel to white else set to black. so would convert the image into black…
Lunar
  • 4,663
  • 7
  • 43
  • 51
46
votes
1 answer

Using Graphics2D to overlay text on a BufferedImage and return a BufferedImage

I have checked similarly named questions, but they don't answer this use case. Basically, I was to overlay some text (text) at a given coordinate (x,y) I have the below function in a package; protected BufferedImage Process2(BufferedImage image){ …
Bolster
  • 7,460
  • 13
  • 61
  • 96
44
votes
4 answers

Is storing Graphics objects a good idea?

I'm currently in the process of writing a paint program in java, designed to have flexible and comprehensive functionalities. It stemmed from my final project, that I wrote overnight the day before. Because of that, it's got tons and tons of bugs,…
Zizouz212
  • 4,908
  • 5
  • 42
  • 66
43
votes
2 answers

How do I properly load a BufferedImage in java?

Okay, so I've been trying to load a BufferedImage using this code: URL url = this.getClass().getResource("test.png"); BufferedImage img = (BufferedImage) Toolkit.getDefaultToolkit().getImage(url); This gives me a type cast error when I run it…
William
  • 8,630
  • 23
  • 77
  • 110
1
2 3
99 100