• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get byte[] from the Image?

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone give me a hint on how to a get a byte[] array or InputStream from the Image/Icon object. Need to store an image that doesn't come from the filesytem in the DB's LONG RAW field. I can get int[] with PixelGrabber class, but how does one convert it to byte[]? thanks...
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please try this:

Good luck
Tom
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a similar problem:
I want to convert an java.awt.image into a byte array NOT into an int array. Shouldn't there be a way to specify a custom colorspace and colormodel to pixelgrabber so that it grabs the pixels and puts them into a byte array opposed to a int array??? Or is this just not possible
The image ONLY exists as a java.awt.image NEVER as anything else so there isn't a prior step that I can intercept (which is how the example above does it)
Thanks
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok this is the sort of problem I am having too. I understand all of the above method apart from the baseClass stuff!?!?! can anyone explain that to me? How I should call this method?

thanks for taking the time to read.

cheers
Martin
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Class argument is the class whose class loader will be asked to locate the file (see getResource Method Detail in Class api). If it is simply the enclosing class you can use the keyword this. If called from a static context you will need to use the MyClass.class form of class reference. If called from within an inner class you can use a member variable reference created at construction.

See the tutorial page How to Use Icons, especialy the section Loading Images Using getResource.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not just write the image out using the javax.imageio.ImageIO which has the following static method:



You're image does get encoded into the format you specify (i.e. jpeg or png for example), which does seem to be a good side-effect.

Take a peek at the
Java Almanac.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic