Android -OutofMemory error- bitmap factory -


my code..

mimageview_photos.setimagebitmap(bitmapfactory.decodefile(picturepath)); 

my logcat..

11-27 10:51:56.325: e/androidruntime(3879): fatal exception: main 11-27 10:51:56.325: e/androidruntime(3879): process: com.virtualmaze.golfelite, pid: 3879 11-27 10:51:56.325: e/androidruntime(3879): java.lang.outofmemoryerror 11-27 10:51:56.325: e/androidruntime(3879):     @ android.graphics.bitmapfactory.nativedecodestream(native method) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.graphics.bitmapfactory.decodestreaminternal(bitmapfactory.java:620) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:596) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.graphics.bitmapfactory.decodefile(bitmapfactory.java:376) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.graphics.bitmapfactory.decodefile(bitmapfactory.java:402) 11-27 10:51:56.325: e/androidruntime(3879):     @ com.virtualmaze.golfelite.holemapactivity.createimageview(holemapactivity.java:3839) 11-27 10:51:56.325: e/androidruntime(3879):     @ com.virtualmaze.golfelite.holemapactivity.onactivityresult(holemapactivity.java:3762) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.app.activity.dispatchactivityresult(activity.java:5423) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.app.activitythread.deliverresults(activitythread.java:3347) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.app.activitythread.handlesendresult(activitythread.java:3394) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.app.activitythread.access$1300(activitythread.java:135) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.app.activitythread$h.handlemessage(activitythread.java:1244) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.os.handler.dispatchmessage(handler.java:102) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.os.looper.loop(looper.java:136) 11-27 10:51:56.325: e/androidruntime(3879):     @ android.app.activitythread.main(activitythread.java:5001) 11-27 10:51:56.325: e/androidruntime(3879):     @ java.lang.reflect.method.invokenative(native method) 11-27 10:51:56.325: e/androidruntime(3879):     @ java.lang.reflect.method.invoke(method.java:515) 11-27 10:51:56.325: e/androidruntime(3879):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) 11-27 10:51:56.325: e/androidruntime(3879):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) 11-27 10:51:56.325: e/androidruntime(3879):     @ dalvik.system.nativestart.main(native method) 

how can rectify this?

when image size big shows java.lang.outofmemoryerror

try solutions ,

1) can use android-universal-image-loader library set images efficiently, nice solution

or

2) can shrink bitmap size before use it...

bitmapfactory.options bmpfactoryoptions = new bitmapfactory.options(); bmpfactoryoptions.injustdecodebounds = true; bitmap bitmap = bitmapfactory.decodefile(file, bmpfactoryoptions);  int heightratio = (int) math.ceil(bmpfactoryoptions.outheight / (float) height); int widthratio = (int) math.ceil(bmpfactoryoptions.outwidth / (float) width);  if(heightratio > 1 || widthratio > 1) {     if(heightratio > widthratio)     {         bmpfactoryoptions.insamplesize = heightratio;     }     else     {         bmpfactoryoptions.insamplesize = widthratio;     } }  bmpfactoryoptions.injustdecodebounds = false; bitmap = bitmapfactory.decodefile(file, bmpfactoryoptions); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -