java me - Out of memory error native Image decode Error while loading image to gallery -


i trying load image folder application, code using is

fileconnection fc = null; datainputstream in = null; dataoutputstream out = null;  try {   fc = (fileconnection)connector.open("file:///e:/images/abc.jpg");   int length = (int)fc.filesize();//possible loss of precision may throw error   byte[] data = null;   if (length != -1) {     data = new byte[length];     in = new datainputstream(fc.openinputstream());     in.readfully(data);   }   else {     int chunksize = 112;     int index = 0;     int readlength = 0;     in = new datainputstream(fc.openinputstream());     data = new byte[chunksize];     {       if (data.length < index + chunksize) {         byte[] newdata = new byte[index + chunksize];         system.arraycopy(data, 0, newdata, 0, data.length);         data = newdata;       }       readlength = in.read(data, index, chunksize);       index += readlength;     } while (readlength == chunksize);     length = index;   }   image image = image.createimage(data, 0, length);   image = createthumbnail(image);   imageitem imageitem = new imageitem(null, image, 0, null);   mform.append(imageitem);   mform.settitle("done.");   fc = (fileconnection)connector.open("file:///e:/images/abc.jpg");   if(!fc.exists()){       try{       fc.create();                                                                                                                                                                                     }catch(exception ce){system.out.print("create error: " + ce);}   }   out = new dataoutputstream(fc.openoutputstream());   out.write(data); } catch (ioexception ioe) {   stringitem stringitem = new stringitem(null, ioe.tostring());   mform.append(stringitem);   mform.settitle("done."); } {   try {     if (in != null) in.close();     if (fc != null) fc.close();   }   catch (ioexception ioe) {} 

hope can problem image tried resize image

    private image createthumbnail(image image) {     int sourcewidth = image.getwidth();     int sourceheight = image.getheight();     int thumbwidth = 18;     int thumbheight = 23;      image thumb = image.createimage(thumbwidth, thumbheight);     graphics g = thumb.getgraphics();      (int y = 0; y < thumbheight; y++)     {     (int x = 0; x < thumbwidth; x++)     {     g.setclip(x, y, 1, 1);     int dx = x * sourcewidth / thumbwidth;     int dy = y * sourceheight / thumbheight;     g.drawimage(image, x - dx, y - dy, graphics.left | graphics.top);      }     }      image immutablethumb = image.createimage(thumb);     return immutablethumb; }  

still returns exception out of memmory native image deocde error, pls me sort out

this may occur becuase of 2 reason.

  1. image size: in phones due small heap size not device not load image try smaller image size.

  2. second reason may image corrupt try image.


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -