| Reply | « Previous Thread | Next Thread » |
|
hello friends,
I am developing an app tht sends image to server with help of http multipart request. Nw, I want to convert the image in byte array. Code:
public static byte[] getByteArray(Image image)
{
int raw[] = new int[image.getWidth() * image.getHeight()];
image.getRGB(raw, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
byte rawByte[] = new byte[image.getWidth() * image.getHeight() * 4];
int n = 0;
for(int i = 0; i < raw.length; i++)
{
int ARGB = raw[i];
int a = (ARGB & 0xff000000) >> 24;
int r = (ARGB & 0xff0000) >> 16;
int g = (ARGB & 0xff00) >> 8;
int b = ARGB & 0xff;
rawByte[n] = (byte)b;
rawByte[n + 1] = (byte)g;
rawByte[n + 2] = (byte)r;
rawByte[n + 3] = (byte)a;
n += 4;
}
raw = null;
return rawByte;
}
wt should i do ?? Do I have any othe way to convert an image to byte array ?? |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
Hi,
Can you make sure that how many times this methods executes? Thanks R a j - The K e r n e l |
|
How big is the image (width and height)?
Why do you want to convert it into an array of pixels? Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
thnx for the replay Raj, Grahamhughes
by doing some R&D and paperwork, finally i have removed the posted code with the below new one, Code:
public byte[] getImageBytes(String path)
{
byte[] imgData = new byte[0];
try
{
FileConnection fc = (FileConnection) Connector.open(path, Connector.READ);
InputStream stream = fc.openInputStream();
long File_Size = fc.fileSize();
final int CHUNK = 1;
int length = 0;
while(length < File_Size)
{
byte[] data = new byte[CHUNK];
int readAmount = stream.read(data, 0, CHUNK);
byte[] newImageData = new byte[imgData.length + CHUNK];
System.arraycopy(imgData, 0, newImageData, 0, length);
System.arraycopy(data, 0, newImageData, length, readAmount);
imgData = newImageData;
length += readAmount;
}
}catch(Exception e) {}
return imgData;
}
nw i can read my image file data chunk by chunk. by the way thnx lot 4 the replay. thnx 1s again... :) Good judgment comes from experience, and experience comes from bad judgment.
Last edited by vdx : 2009-04-13 at 13:25.
|
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
Hi,
Since this is a very important thread/subject asked by the developers,so I would appreciate you if can share the solution. Thanks R a j - The K e r n e l |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Image size on 6280 | ariekk | Mobile Java General | 0 | 2008-09-15 07:42 |
| Using Camera API requires too much memory | tote_b5 | Symbian Media (Graphics & Sounds) | 18 | 2008-07-31 17:21 |
| Excessive midlet memory consumption | paulip | Mobile Java General | 1 | 2007-10-09 20:24 |
| --- ???save image problem??? --- | ferenn | Mobile Java Media (Graphics & Sounds) | 6 | 2007-10-01 15:33 |
| show image on the form from memory | aaapigfly | Mobile Java Media (Graphics & Sounds) | 2 | 2007-08-27 21:15 |