[英]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
. 我想在将图像设置为
imageview
之前设置图像的样本大小。 The problem is, that my application crashes if I set the image directly to imageview
. 问题是,如果将图像直接设置为
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: 谢谢Candide的帮助,现在它可以与以下代码一起使用:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.