0

Can someone post the android gallery example where bitmap properties are used. I am new to it so cant figure out how it works. I have gallery without bitmap which gives memory error. Please post example where it does not lead to memory error

Error Log is

05-14 15:33:25.336: E/AndroidRuntime(563): FATAL EXCEPTION: main
05-14 15:33:25.336: E/AndroidRuntime(563): java.lang.OutOfMemoryError
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.content.res.Resources.loadDrawable(Resources.java:1937)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.content.res.Resources.getDrawable(Resources.java:664)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.ImageView.resolveUri(ImageView.java:542)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.ImageView.setImageResource(ImageView.java:315)
05-14 15:33:25.336: E/AndroidRuntime(563):  at com.hospital.ImageAdapter.getView(ImageAdapter.java:46)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.makeAndAddView(Gallery.java:844)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:798)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.fillToGalleryRight(Gallery.java:742)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.layout(Gallery.java:651)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.onLayout(Gallery.java:346)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.os.Looper.loop(Looper.java:137)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-14 15:33:25.336: E/AndroidRuntime(563):  at java.lang.reflect.Method.invokeNative(Native Method)
05-14 15:33:25.336: E/AndroidRuntime(563):  at java.lang.reflect.Method.invoke(Method.java:511)
05-14 15:33:25.336: E/AndroidRuntime(563):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-14 15:33:25.336: E/AndroidRuntime(563):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-14 15:33:25.336: E/AndroidRuntime(563):  at dalvik.system.NativeStart.main(Native Method)
2
  • check this saigeethamn.blogspot.com/2010/05/… Commented May 14, 2012 at 14:39
  • but it mentions nth about bitmapfactory class Commented May 14, 2012 at 14:48

2 Answers 2

1

To fix OutOfMemory you should do something like that:

BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap preview_bitmap=BitmapFactory.decodeStream(is,null,options);

also see this

https://stackoverflow.com/a/823966/985143

Sign up to request clarification or add additional context in comments.

Comments

0

see this new resource added on developer site : http://developer.android.com/training/displaying-bitmaps/index.html (check the example project on right side of the screen)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.