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
41
votes
3 answers

Create a BufferedImage from file and make it TYPE_INT_ARGB

I have a PNG file with transparency that is loaded and stored in a BufferedImage. I need this BufferedImage to be of TYPE_INT_ARGB. However, when I use getType() the returned value is 0 (TYPE_CUSTOM) instead of 2 (TYPE_INT_ARGB). This is how I load…
user1319734
  • 427
  • 1
  • 4
  • 7
37
votes
4 answers

How to check a uploaded file whether it is an image or other file?

In my web application I have an image uploading module. I want to check the uploaded file whether it's an image file or any other file. I am using Java in server side. The image is read as BufferedImage in java and then I am writing it to disk with…
user405398
36
votes
5 answers

How to convert a byte[] to a BufferedImage in Java?

I'm posting this thread because I have some difficulties to deal with pictures in Java. I would like to be able to convert a picture into a byte[] array, and then to be able to do the reverse operation, so I can change the RGB of each pixel, then…
Jef Grailet
  • 547
  • 1
  • 5
  • 7
35
votes
9 answers

Converting `BufferedImage` to `Mat` in OpenCV

How can I convert a BufferedImage to a Mat in OpenCV? I'm using the JAVA wrapper for OpenCV(not JavaCV). As I am new to OpenCV I have some problems understanding how Mat works. I want to do something like this. (Based on Ted W.…
Jompa234
  • 1,228
  • 2
  • 14
  • 24
30
votes
5 answers

Java BufferedImage to PNG format Base64 String

I'm trying to get a screenshot output as a base64 encoded string but not getting very far. The code I have so far uses a Base64 library ( http://iharder.sourceforge.net/current/java/base64/ ): Robot robot = new Robot(); Rectangle r = new…
user72003
  • 425
  • 1
  • 5
  • 7
30
votes
1 answer

How do I convert a InputStream to BufferedImage in Java/Groovy?

Yes, I'm that stupid. I'm trying to stick some groovy code together from various cookbook recipes, and I can't get from an InputStream to BufferedImage in Java/Groovy. Google is not being my friend at present.
Dycey
  • 4,767
  • 5
  • 47
  • 86
29
votes
6 answers

Java- Convert bufferedimage to byte[] without writing to disk

I'm trying to send multiple images over a socket using java but I need a faster way to convert the images to a byte array so I can send them. I tried the following code but it wrote about 10,000 images to my C:\ drive. Is there a way to make this…
tier1
  • 6,303
  • 6
  • 44
  • 75
28
votes
3 answers

Difference between the Image and BufferedImage in Java

What is the difference between Image and BufferedImage? Can I create a BufferedImage directly from an Image source "image.png"?
Tofiq
  • 2,901
  • 6
  • 26
  • 34
27
votes
5 answers

Set BufferedImage to be a color in Java

I need to create a rectangular BufferedImage with a specified background color, draw some pattern on the background and save it to file. I don't know how to create the background. I am using a nested loop: BufferedImage b_img = ... for every row for…
Lily
  • 5,872
  • 19
  • 56
  • 75
25
votes
3 answers

How can you produce sharp paint results when rotating a BufferedImage?

One attempted approach was to use TexturePaint and g.fillRect() to paint the image. This however requires you to create a new TexturePaint and Rectangle2D object each time you paint an image, which isn't ideal - and doesn't help anyway. When I use…
rtheunissen
  • 7,347
  • 5
  • 34
  • 65
25
votes
1 answer

Is there a way to create one Gif image from multiple images in Java?

I am trying to set up a simple Java program that creates one single animated gif from multiple other images (jpg). Can anyone give me a hook on how to achieve this in Java? I already searched Google but couldn't find anything really helpful. Thank…
user2399314
  • 521
  • 3
  • 8
  • 9
25
votes
5 answers

Convert BufferedImage to ImageIcon

How can I convert a BufferedImage to an ImageIcon? I can not find any documentation on this.
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
24
votes
6 answers

How to convert buffered image to image and vice-versa?

Actually i am working on a image editing software and now i want to convert the buffered-image i.e : BufferedImage buffer = ImageIO.read(new File(file)); to Image i.e in the format something like : Image image = ImageIO.read(new…
Arizvi
  • 261
  • 1
  • 5
  • 13
22
votes
7 answers

Convert each animated GIF frame to a separate BufferedImage

I want to be able to take an animated GIF as input, count the frames (and perhaps other metadata), and convert each to a BufferedImage. How can I do this?
Marty
  • 2,104
  • 2
  • 23
  • 42
22
votes
4 answers

How to convert BufferedImage to InputStream?

I am uploading images using servlet. To perform resize operations i am converting InputStream to BufferedImage. Now i want to save it in mongoDB. Since, i am new to mongoDB as far as i know, GridFS takes InputStream. So, is there any way to convert…
user405398