【问题标题】:Threading Bitmap Decoding & assigning Bitmap to an ImageView线程位图解码并将位图分配给 ImageView
【发布时间】: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


    【解决方案1】:

    使用 AsyncTask...

    您可以在

    上找到它的工作原理说明

    http://developer.android.com/training/displaying-bitmaps/index.html

    重要的是,也请阅读 4 个子主题。

    卢卡斯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多