android - Getting Out of memory error when reading images from SDcard -
i developing simple application imageview, when imageview clicked application should open device image gallery. achieve using following code
intent imageintent=new intent(intent.action_pick); imageintent.settype("image/*"); startactivityforresult(imageintent,5);
and activityresult
super.onactivityresult(requestcode, resultcode, data); if(requestcode == 5) { cursor cursor; uri uri=data.getdata(); if(uri!=null) { cursor=getcontentresolver().query(uri, new string[]{ android.provider.mediastore.images.imagecolumns.data }, null, null, null); cursor.movetofirst(); string imageid=cursor.getstring(0); personimage.setimageuri(uri); log.i("imageid", ""+imageid); cursor.close(); } }
the selected image displayed in imageview. problem when doing second time getting following exception.
12-01 19:31:52.344: error/androidruntime(2011): fatal exception: main 12-01 19:31:52.344: error/androidruntime(2011): java.lang.outofmemoryerror: bitmap size exceeds vm budget 12-01 19:31:52.344: error/androidruntime(2011): @ android.graphics.bitmapfactory.nativedecodestream(native method) 12-01 19:31:52.344: error/androidruntime(2011): @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:468) 12-01 19:31:52.344: error/androidruntime(2011): @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:332) 12-01 19:31:52.344: error/androidruntime(2011): @ android.graphics.drawable.drawable.createfromresourcestream(drawable.java:697) 12-01 19:31:52.344: error/androidruntime(2011): @ android.graphics.drawable.drawable.createfromstream(drawable.java:657) 12-01 19:31:52.344: error/androidruntime(2011): @ android.widget.imageview.resolveuri(imageview.java:572) 12-01 19:31:52.344: error/androidruntime(2011): @ android.widget.imageview.setimageuri(imageview.java:293) 12-01 19:31:52.344: error/androidruntime(2011): @ com.css.testsample.readimage.onactivityresult(readimage.java:36) 12-01 19:31:52.344: error/androidruntime(2011): @ android.app.activity.dispatchactivityresult(activity.java:3931) 12-01 19:31:52.344: error/androidruntime(2011): @ android.app.activitythread.deliverresults(activitythread.java:3730) 12-01 19:31:52.344: error/androidruntime(2011): @ android.app.activitythread.handlesendresult(activitythread.java:3776) 12-01 19:31:52.344: error/androidruntime(2011): @ android.app.activitythread.access$2800(activitythread.java:135) 12-01 19:31:52.344: error/androidruntime(2011): @ android.app.activitythread$h.handlemessage(activitythread.java:2166) 12-01 19:31:52.344: error/androidruntime(2011): @ android.os.handler.dispatchmessage(handler.java:99) 12-01 19:31:52.344: error/androidruntime(2011): @ android.os.looper.loop(looper.java:144) 12-01 19:31:52.344: error/androidruntime(2011): @ android.app.activitythread.main(activitythread.java:4937) 12-01 19:31:52.344: error/androidruntime(2011): @ java.lang.reflect.method.invokenative(native method) 12-01 19:31:52.344: error/androidruntime(2011): @ java.lang.reflect.method.invoke(method.java:521) 12-01 19:31:52.344: error/androidruntime(2011): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 12-01 19:31:52.344: error/androidruntime(2011): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 12-01 19:31:52.344: error/androidruntime(2011): @ dalvik.system.nativestart.main(native method)
i dont know how handle problem, if knows please me.
thanks , regards, rajapandian.k
try downsampling images shown here
Comments
Post a Comment