04-13-2011 10:13 AM
Hello,
I've been unable to find a post that details how to retrieve the image bytes from an image (given the file path of the image on the device). Basically, using the FilePicker, I'm able to get the path of an image that the user chooses:
Now, I'm looking to get the bytes for this image, so that I can send it to a server. Can anyone provide me with some sample code, or perhaps refer me to another post?
Thank you.
Solved! Go to Solution.
04-13-2011 10:15 AM
There you go:
just pass your filename as the method parameter.
public static byte[] getBytesFromFile(String filename) throws IOException {
FileConnection fconn = null;
InputStream is = null;
try {
fconn = (FileConnection) Connector.open(filename, Connector.READ);
is = fconn.openInputStream();
return IOUtilities.streamToBytes(is);
} finally {
if (is != null) {
is.close();
}
if (fconn != null) {
fconn.close();
}
}
}
04-13-2011 10:23 AM
Perfect, I appreciate your help! Thanks!
04-13-2011 10:53 AM
Another question:
Is filename meant only to be the filename (image.png), or can it be a path (as I showed as an example in my original post)?
The reason that I ask is because here is the output of the bytes from an example image:
[B@81a6843f
That looks more like a pointer to me than actual bytes describing an image, no?
04-13-2011 02:26 PM
the path name only applies