Obtaining byte from Image
first of all, sorry because this is probably kinda off-topic. I have an Image and I want to get the byte to send it to a Servlet. The only method I found is Image.getRGB() which returns and int (ARGB). Now, how I can convert this int into byte? I don't care about alpha channel.
I tried this:
<br /> int j=0;<br /> int dat = imgPreview.getRGB();</p> <p>byte data = new byte[dat.length*3]; //only RGB</p> <p>for (int i=0;i> 16);<br /> data[j++] = (byte)((dat[i] & 0x0000FF00) >> 8);<br /> data[j++] = (byte)((dat[i] & 0x000000FF));<br /> }<br />
And I don't see this working as expected.
On the other hand, I think this int is raw (without format) ARGB, so it wouldn't be possible to create the image again using Image.createImage(byte, offset, len) if the byte were created successfully.
Why all this?
I'm taking a snapshot and saving as an Image instead of byte because I need to show the image in one screen and rescaled in another one. So I thought it would be better to store the Image instead of the byte (which was my previous choice, but then you must createImage 2 times.
And when I need to send the image to the server, I want to use the byte. Any idea on how to obtain it? Or it's just better to store the byte and createImage everytime is needed?
Thanks in advance.