permaculture playing cards*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

how to save a image in j2me

sankar ganesh
Greenhorn

Joined: Jun 07, 2005
Posts: 20
hi,
i'm trying to do some image processing in j2me.in that i display one image in canvas and make that one as negative image and also display that negative image in the canvas.now 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
Greenhorn

Joined: Jul 29, 2005
Posts: 3
Hi,
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);
dos.writeString(imgName);
for (int i = 0; i < imgRgbData.length; i++) {
dos.writeInteger(imgRgbData);
}

// 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
rs.closeRecordStore();
} 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
Greenhorn

Joined: Jun 07, 2005
Posts: 20
hi
thanx a lot for ur reply and coding.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to save a image in j2me
 
Similar Threads
image processing with jpeg in j2me
Saving picture from the phone's camera
Capacity of RMS in Mobile
storing image in resource folder
image uploading in Jsp