2012-05-14 44 views
0

有人可以發佈使用位圖屬性的android圖庫示例。我對它很陌生,所以無法弄清楚它是如何工作的。我有沒有位圖的畫廊,這給內存錯誤。請張貼例如其中不導致內存不足的錯誤使用位圖類的Android圖庫

錯誤日誌是

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) 
+0

檢查這個http://saigeethamn.blogspot.com/2010/05/gallery-view-android-developer-tutorial.html –

+0

但它提到關於bitmapfactory類的第n個 – rdevil

回答

1

要解決內存不足,你應該做這樣的事情:

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

也看到這個

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