File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java Micro Edition and the fly likes how to save a image in j2me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "how to save a image in j2me" Watch "how to save a image in j2me" New topic

how to save a image in j2me

sankar ganesh

Joined: Jun 07, 2005
Posts: 20
i'm trying to do some image processing in that i display one image in canvas and make that one as negative image and also display that negative image in the i want to save that image.while using rms to store the image the rms stores the image that is already in the resource folder only.
please tell me if any knows how to save the image.
also i tried with file connection api in that i'm able to append a text data.but don't know how to store the image.onemore condition while using is fileconnection is supported by CLDC1.1 only this configuration is rare in mobiles.
please anyone knows the solution then help me
thanx a lot in advance
amar pashya

Joined: Jul 29, 2005
Posts: 3
If u want to store that in RMS then just get the integer array of the image using getRGB() method and the you can store it to the RMS using the streams.

boolean addImageToRecordStore(Image img, int width, int height, String rsName, String imgName) {
if (img == null || width < 0 || height < 0 || rsName == null || rsName.length == 0 || imgName == null) {
throw new IllegalArgumentException("Check arguments");

if (width > img.getWidth()) {
width = imgWidth;

if (height > img.getHeight()) {
height = imgHeight;

int[] imgRgbData = new int[width * height];

try {
img.getRgb(imgRgbData, 0, width, 0, 0, w, h);
} catch (Exception e) {
// Problem getting image RGB data

return false;

try {
// Write image data to output stream (in order to get the record bytes in needed form)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputImpl(dos);
for (int i = 0; i < imgRgbData.length; i++) {

// Open record store, create if it doesn't exist
RecordStore rs = RecordStore.openRecordStore(name, true);
rs.addRecord(baos.toByteArray(), 0, baos.toByteArray().length); // Add record
} catch (RecordStoreNotFoundException rsnfe) {
// Record storage not found
return false;
} catch (RecordStoreException rse) {
// Other record storage problem
return false;
} catch (IOException ioe) {
// Problem writing data
return false;

return true; // We've successfuly done

I hope this code will help you
sankar ganesh

Joined: Jun 07, 2005
Posts: 20
thanx a lot for ur reply and coding.
I agree. Here's the link:
subject: how to save a image in j2me
It's not a secret anymore!