Forums Register Login

How to get byte[] from the Image?

+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
Please try this:

Good luck
Tom
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3458 times.
Similar Threads
Image object to png Image format
How to Upload Image in to Server?
Java2D: byte[ ] from an Image
Send Image to web service
How to get byte[] from the Image
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:44:10.