converting image to byte[] in cldc, midp2.0 devices
Hello Friends,
I need to convert a image to byte[] for sending an image to server. can anyone suggest me any solution. I am developing on MOTOROKR E 6 handset.
i have already searched whole net & even methods on this thread didn't help me.
http://forum.java.sun.com/thread.jspa?threadID=617676&tstart=120
The fuzz is that the mobile is running Linux OS & emulator started giving Null Pointer Exceptions when i tried to implement a few methods( i don't know why)
Also when i passed a static byte[] of captured image to connection thread it again yelled Null Pointer Exception.
I am sick of this mobile pulling my hairs since last 4 days. so plz help me
thanks a lot
Rahul
# 2
Thanks for replying
well i tried it this way
int[] byteArray = new byte[width*height*4]; //assuming we store Alpha
int[] rgbArray = new int[width*height];
myImage.getRGB(rgbArray, 0, width, 0, 0, width, height);
for(int i=0; i<rgbArray.length*4; i+4)
{
byteArray[i+0] = (rgbArray[i/4] >> 24);
byteArray[i+1] = (rgbArray[i/4] >> 16) & 0x000000FF;
byteArray[i+2] = (rgbArray[i/4] >> 8) & 0x000000FF;
byteArray[i+3] = rgbArray[i/4] & 0x000000FF;
}
but it gave a array out of bound exception
# 3
I don't know why?
maybe your width and height are not assigned the width and height of the image first.
but your code seems to have problems.
what's it ?
int[] byteArray = new byte[width*height*4];
why you asssigned an int array a byte one.
and in this line
for(int i=0; i < rgbArray.length*4; i+4)
i+4 does not change the value of i.
I think you should do this.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
for(int j = 0 ; j<rgbArray.length ; j++)
dos.writeInt(rgbArray[j]);
byteArray = baos.toByteArray();>
etaa at 2007-7-28 18:40:21 >
