Dermofit
asked on
How to save an image in J2ME
I have an edited image on an Image object.
How o I save that image to the cellphone's memory card? I don't care what format. Any will do (png, jpg, gif, etc).
How o I save that image to the cellphone's memory card? I don't care what format. Any will do (png, jpg, gif, etc).
Let me know what progress you do/don't make with this. I haven't done it so it would be good to know.
Thanks
Also,
file:///root1/ is the temp directory where the image needs to be located when testing with emulator.
when you run the emulator you will see an output line in the console that indicates where your "storage root" is located.
What I do is start the emulator, but before launching the Midlet navigate to the temp directory and drop the image file in. I don't know of a better/automatic way to have the image generated in the temp directory.
Thanks
Also,
file:///root1/ is the temp directory where the image needs to be located when testing with emulator.
when you run the emulator you will see an output line in the console that indicates where your "storage root" is located.
What I do is start the emulator, but before launching the Midlet navigate to the temp directory and drop the image file in. I don't know of a better/automatic way to have the image generated in the temp directory.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use a single fileconnection on multiple files and/or create the file if it does not exist as follows:
fc = (FileConnection)Connector. open("file :///root1/ saved.PNG" );
if(!fc.exists()){
fc.create();
}
fc = (FileConnection)Connector.
if(!fc.exists()){
fc.create();
}
http://developers.sun.com/mobility/apis/articles/fileconnection/
http://developers.sun.com/mobility/apis/ttips/fileconnection/
You need to save/load the image via byte streams.
This example loads an image from over the network:
http://www.java2s.com/Code/Java/J2ME/ImageLoader.htm
The principles are the same, but instead of HttpConnection you want to use FileConnection.
I haven't tried it, but this looks promising:
http://ce.sharif.edu/~p_amini/j2me/JPEG_Encoder
The code is difficult to follow, but it may help.
I tried to rework this code found at http://www.coderanch.com/t/229101/Java-Micro-Edition/java/jme-upload-image-file-captured but haven't enough time/expertise to get it running:
Open in new window