繁体   English   中英

加载位图图像-Xamarin.Andoird

[英]Loading BitMap Images - Xamarin.Andoird

我正在我的应用程序中执行位图调整大小。 我有一个名为“位图图像”的文件夹,该文件夹具有启动位图调整大小的功能。 但是在我的适配器(这一行代码)中, hold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(getResources(),news[position].Image,100,100)); ,第一个参数getResource作为错误引发。 什么东西少了?

public class MyAdapter : RecyclerView.Adapter

    {
        private JavaList<News> news;



        public MyAdapter(JavaList<News> news)
        {
            this.news = news;

        }

        //binding data to views
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            MyHolder hold = holder as MyHolder;
            hold.Comment.Text = news[position].Comment;
            //hold.Img.SetImageResource(news[position].Image);
            hold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(getResources(),news[position].Image,100,100));


        }

问题是您没有传递Context 要访问getResources()您必须传递Context 因此,修改您的适配器类。

public class MyAdapter : RecyclerView.Adapter

{
    private JavaList<News> news;
    private Context context;



    public MyAdapter(JavaList<News> news, Context context)
    {
        this.news = news;
        this.context = context;
    }

   ......
 //Then in your OnBindViewHolder you can call getResources
  .....
   hold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(context.getResources(),news[position].Image,100,100));
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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