|
Replies:
10
-
Last Post:
Mar 22, 2009 5:58 AM
by: Shai Almog
|
|
|
|
|
|
|
Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 5:07 AM
|
|
|
Hi ppl, I'm really stumped on this one, been looking at it for days and can't work it out. My code simply creates an image using an inputstream from a fileconnection. It all works fine on a SE but not on a Nokia S40?? Code snippet below...
private Image loadImage(String name) { Image loadedImage = null; try { FileConnection connection = (FileConnection) Connector.open("file://localhost/" + currDirName + name, Connector.READ);
InputStream iStrm = connection.openInputStream();
//fails on the following line, createImage returns null loadedImage = Image.createImage(iStrm);
iStrm.close(); connection.close(); } catch (java.io.IOException ex) { ex.printStackTrace(); } return loadedImage; }
The fullpath of Connector.open is... file://localhost/C:/predefgallery/predefphotos/DSC00040.JPG
This is running on Series 40 5th Edidtion SDK from Nokia, it also doesn't work on an S40 device.
Emulator is set to Trusted/Maximum.
Any ideas??
Message was edited by: robovanbasten
Message was edited by: robovanbasten
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 5:18 AM
in response to: robovanbasten
|
|
|
I suggest you change the path to file:///C:/predefgallery/predefphotos/DSC00040.JPG, leaving out the localhost part of the string. Regards, Thorsten.
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 7:45 AM
in response to: thorsten_s
|
|
|
Hi thorsten_s, I tried that, still no joy - it simply can't createImage from my InputStream?? Any other suggestions? Chris
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 7:48 AM
in response to: robovanbasten
|
|
|
//fails on the following line, createImage returns null loadedImage = Image.createImage(iStrm);
Message was edited by: robovanbasten
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 8:18 AM
in response to: robovanbasten
|
|
|
After further investigation it seems that there is a limitation of the size of file, not sure if this is size in terms of bytes or width*height. I guess SE allows more memory for image manipulation?
Anyone else come across this problem?
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 8:45 AM
in response to: robovanbasten
|
|
|
Try this out and c if that makes any difference. Instead of getting the inputstream get the datainputstream then use readfully.
byte imageData[]; final int length = (int) connection.getLength();
if (length != -1) { imageData = new byte[length]; iStrm.readFully(imageData); } else { bStrm = new ByteArrayOutputStream();
int ch; while ((ch = iStrm.read()) != -1) bStrm.write(ch); imageData = bStrm.toByteArray(); }
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 8:57 AM
in response to: pakmee
|
|
|
connection does not have a getLength() property?
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 9:02 AM
in response to: pakmee
|
|
|
Try availablesize. You can also try to add the following
call the exist method on the connection obj to know if the connection exists. If it doesn't then the problem lies with the path.
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 17, 2009 12:42 PM
in response to: robovanbasten
|
|
|
try dropping the Connector.READ parameter
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 19, 2009 11:32 AM
in response to: myinstinct
|
|
|
Cheers for the responses ppl,
I tried dropping the Connector.READ parameter, but that didn't help.
My connection is definitely valid, as I can see fileSize, lastModified etc, hence my path to the file must be correct.
As I mentioned, it seems that there is a limitation to the size (in kb's) of the image you can load. It works fine on a SE, but not on a Nokia S40.
After some basic testing it looks like if the image (that you've taken with the phones camera) is more than about 50kb then Image.creatImage(InputStream) returns null, if I take that same image and edit it on my PC to half the size (i.e. reducing it's size) then it will load no problem!
Does anyone know what the threshold is on an Nokia S40?
|
|
|
|
|
|
|
|
Re: Image.createImage(InputStream) not working on Nokia
Posted:
Mar 22, 2009 5:58 AM
in response to: robovanbasten
|
|
|
|
|
Many mobile phones don't allow you to load images created with their own cameras. This is a problem with the phone that exists in MIDP applications as well and should be taken up with the manufacturers. E.g. a 2mp camera phone which is pretty much the minimum today might require 4 bytes per pixel to load the image hence 8mb of RAM which few phones have available for applications (notice a 16gb phone means storage not RAM). This leads to ironic situations where you can't display the image you just shot with the camera using MMAPI...
AFAIK MajiPic from majimob ( http://majimob.com/majimo/applications/ pics.html ) solved this by building their own in house JPEG decoder.
Modern Series 40 devices typically have 2MB allocated for applications out of which the GameCanvas takes 350kb (this is discussed in the blog quite a bit).
> Cheers for the responses ppl, > > I tried dropping the Connector.READ parameter, but that didn't help. > > My connection is definitely valid, as I can see fileSize, > lastModified etc, hence my path to the file must be correct. > > As I mentioned, it seems that there is a limitation to the size (in > kb's) of the image you can load. It works fine on a SE, but not on > a Nokia S40. > > After some basic testing it looks like if the image (that you've > taken with the phones camera) is more than about 50kb then > Image.creatImage(InputStream) returns null, if I take that same > image and edit it on my PC to half the size (i.e. reducing it's > size) then it will load no problem! > > Does anyone know what the threshold is on an Nokia S40? > [Message sent by forum member 'robovanbasten' (robovanbasten)] > > http://forums.java.net/jive/thread.jspa?messageID=338000 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net > For additional commands, e-mail: users-help@lwuit.dev.java.net >
Shai Almog http://lwuit.blogspot.com/ https://lwuit.dev.java.net/faq.html
[att1.html]
|
|
|
|
|