【发布时间】:2014-05-13 13:16:53
【问题描述】:
下面的代码不显示图像,如果我删除线程它可以工作,但加载时间会增加。我该如何解决这个问题?
活动:
_imgFoo = new ImageView(this);
//layoutparams are set
ThreadPool.QueueUserWorkItem (o => {
using (var bmp = ImageResizer.DecodeSampledBitmapFromResource (Resources,
Resource.Drawable.exampleimage, width, height)) {
RunOnUiThread (() => _imgFoo.SetImageBitmap (bmp));
bmp.Dispose ();
}
});
图像调整器类:
public static Bitmap DecodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight)
{
// First decode with inJustDecodeBounds=true to check dimensions
var options = new BitmapFactory.Options {
InJustDecodeBounds = true,
};
using (var dispose = BitmapFactory.DecodeResource(res, resId, options)) {
}
// Calculate inSampleSize
options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.InJustDecodeBounds = false;
return BitmapFactory.DecodeResource(res, resId, options);
}
【问题讨论】:
标签: android bitmap xamarin.android xamarin threadpool