This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to save a image in j2me

 
sankar ganesh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
thanx a lot for ur reply and coding.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic