简体   繁体   中英

Monodroid: Set imageview image from file in assets or Resources/drawable to configure SampleSize

I want so set the samplesize of my image before I set it to the imageview . The problem is, that my application crashes if I set the image directly to imageview . (because needs too much memory!?)

Here's my code:

ImageView iv = FindViewById<ImageView>(Resource.Id.imagePusher);
Android.Graphics.BitmapFactory.Options options = new Android.Graphics.BitmapFactory.Options();
options.InSampleSize = 2;

Android.Graphics.Bitmap bMap = Android.Graphics.BitmapFactory.DecodeFile("the_path_I_want_to_know/image.jpg", options);

iv.SetImageBitmap(bMap);

Thank you Candide for help, now it works with the following code:

ImageView iv = FindViewById<ImageView>(Resource.Id.imagePusher);

Android.Graphics.BitmapFactory.Options options = new Android.Graphics.BitmapFactory.Options();
options.InSampleSize = 2;

Stream bitmap = Assets.Open("myimage.jpg");

Android.Graphics.Bitmap bMap = Android.Graphics.BitmapFactory.DecodeStream(bitmap, null, options);


iv.SetImageBitmap(bMap);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM