• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to save a image in j2me

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
thanx a lot for ur reply and coding.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic