Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Image to BufferedImage

Reply
Thread Tools

Image to BufferedImage

 
 
Martin Thomas
Guest
Posts: n/a
 
      06-02-2004
Hi,

simple question and hopefully a simple solution:
How can i convert an java.awt.Image into a BufferedImage?

Thanks

Martin
 
Reply With Quote
 
 
 
 
VisionSet
Guest
Posts: n/a
 
      06-02-2004

"Martin Thomas" <hiwimll7-remove-this-> wrote in message
news:40bdd448$...
> Hi,
>
> simple question and hopefully a simple solution:
> How can i convert an java.awt.Image into a BufferedImage?
>


Chances are it already is!

BufferedImage is the single concrete subclass of Image (in current 1.4.2
API).

cast it to BufferedImage in a safe manner.

Other possibility is a VolatileImage from which you can get a BufferedImage
with getSnapshot().

--
Mike W


 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-02-2004
Martin Thomas wrote:
> Hi,
>
> simple question and hopefully a simple solution:
> How can i convert an java.awt.Image into a BufferedImage?


If you are lucky, a cast will do. If not, if you really have an unknown
Image subclass, well it's not fun:

* Get the Image's consumer with Image.getSource().

* Use a PixelGrabber to read the image data from the consumer into some
pixel array

* Create a DataBufferInt from the pixel data

* Create a WritableRaster using the DataBufferInt

* Create a BufferedImage using the WritableRaster

* curse, wait, curse, wait, curse, curse, curse


There might be better ways.

/Thomas
 
Reply With Quote
 
Adam
Guest
Posts: n/a
 
      06-03-2004
> Hi,
>
> simple question and hopefully a simple solution:
> How can i convert an java.awt.Image into a BufferedImage?


If it is not already a BufferedImage (check with instanceof)
you can create a new BufferedImage with the same size,
and bufferedImage.getGraphics().drawImage(image, 0 , 0, null);

However I don't know what can possibly happen
if image si not yet fully loaded/decoded.

Adam


 
Reply With Quote
 
Martin
Guest
Posts: n/a
 
      06-03-2004
Tanks to all of you for your answers, very helpful suggetions out here!


Martin
 
Reply With Quote
 
Ex1991 Ex1991 is offline
Junior Member
Join Date: Mar 2009
Posts: 2
 
      03-24-2009
Quote:
Originally Posted by Thomas Weidenfeller
Martin Thomas wrote:[color=blue]

* Use a PixelGrabber to read the image data from the consumer into some
pixel array

* Create a DataBufferInt from the pixel data

* Create a WritableRaster using the DataBufferInt

* Create a BufferedImage using the WritableRaster

* curse, wait, curse, wait, curse, curse, curse


There might be better ways.

/Thomas
This is great, but how do I do this, I need to resize an image for my HighSchools project and I have tried many methods, but how do you do this?
 
Reply With Quote
 
javaNewbie javaNewbie is offline
Junior Member
Join Date: Mar 2011
Posts: 1
 
      03-19-2011
Quote:
Originally Posted by Thomas Weidenfeller View Post
Martin Thomas wrote:[color=blue]

* Get the Image's consumer with Image.getSource().

* Use a PixelGrabber to read the image data from the consumer into some
pixel array

* Create a DataBufferInt from the pixel data

* Create a WritableRaster using the DataBufferInt

* Create a BufferedImage using the WritableRaster

* curse, wait, curse, wait, curse, curse, curse


There might be better ways.

/Thomas
Thanks. That worked!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Image versus BufferedImage Crono Java 1 09-12-2006 03:18 AM
BufferedImage Martijn Mulder Java 8 06-03-2005 04:23 PM
How to minumize a image's size created by java.awt.BufferedImage? MaoXuePeng Java 1 11-24-2004 07:17 AM
Converting a BufferedImage to an Image for the J2ME Wireless Toolkit Aimee J Java 1 07-18-2004 04:29 AM
DirectByteBuffer and BufferedImage for image acquisition Peter Szymanski Java 0 07-09-2003 12:29 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57