Tuesday, March 06, 2007

my j2me camera program snapshots #3

my j2me camera program snapshots #2

my j2me camera program snapshots #1

Code:How to write an image in mmapi

How to write an image in mmapi?

I installed and executed this code in my old fashion nokia 6600.
String name;
int recId; // returned by addRecord but not used
TextField tmp = (TextField)get_saveForm().get(0);
name = tmp.getString();
int width = image.getWidth();
int height = image.getHeight();
byte [] rgbData = pngData;//
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(baos);
try{
imageStore = RecordStore.openRecordStore("myimages",true);//image store name
outputStream.writeUTF(name);
outputStream.writeInt(width);
outputStream.writeInt(height);
outputStream.writeInt(rgbData.length);
for(int i=0;i TO rgbData.length;i++)
outputStream.writeByte(rgbData[i]);//write byte and forget out of memory error!

outputStream.flush();
outputStream.close();
byte[] b = baos.toByteArray();
recId = imageStore.addRecord(b, 0, b.length);
// Alert alert = new Alert("ImageSaved" ,name +" Saved",null,AlertType.INFO);
// Display.getDisplay(midlet).setCurrent(alert,this);
Display.getDisplay(midlet).setCurrent(this);
// System.out.println("Image Saved");
}catch(IOException ioe){
Alert alert = new Alert("Image" ,name +"IOException",null,AlertType.ERROR);
Display.getDisplay(midlet).setCurrent(alert,this);
}
catch (Exception e) {
// Log the exception
Alert alert = new Alert("Image" ,name +" Not Saved",null,AlertType.ERROR);
Display.getDisplay(midlet).setCurrent(alert,this);
} finally {
try {
// Close the Record Store
if (imageStore != null) imageStore.closeRecordStore();
} catch (Exception ignore) {
// Ignore
Alert alert = new Alert("Exception" ,ignore.getMessage(),null,AlertType.ERROR);
Display.getDisplay(midlet).setCurrent(alert,this);
}
}

}

TO will be '<' i cant write because of HTML error of silly blogspot editor

getsnapshot(null) problem in nokia6600

In java spec it write that when you give imagetype null your mobile phone take snapshot in default imagetype, but forget it!!! when simply you copy paste code and store it via RMS and later try to retrieve it you ll get an exception!.Where did it come? In Netbeans IDE 5.5 you dont get an exception but when you decide to install and execute your .jar program it simply throw an exception even simply wrote a meaningful expression abou what exception is. Try - catch blocks doesnt really do not anything in my nokia66oo and you can't see anything about problem. You will get an exception which see Exception 0 (oh really??)If you have a problem like this i suggest you give up studying and simply give more attention to your girlfriend :)) When you get ready (your mind is free) look at your device specification then you will get the answer.If you don't get anything,write a better code and give up cursing

Monday, March 05, 2007

getSnapshot(java.lang.String imageType) in mmapi

getSnapshot(java.lang.String imageType) returns a byte array which is encoded with given imageType.If imageType is null then default image type will be used.

How to learn supported image types?

System.out.println(System.getProperty("video.snapshot.encodings"));

Getting a jpeg image

byte[] imageData = videoControl.getSnapshot("encoding=jpeg"); //160x120
byte[] imageData = videoControl.getSnapshot("encoding=jpeg width="200" height="150");

Getting a png image

byte[] imageData = videoControl.getSnapshot("encoding=png"); //160x120

image types

http://en.wikipedia.org/wiki/Png

A good comparison of snapshot speed of the Nokia 6600 in different image types



Sunday, March 04, 2007

Code example for RMS in j2me

An example code shows how to store and load png images