Xamarin系统不了解Android.Graphics.Bitmap

时间:2016-12-06 17:39:10

标签: android xamarin bitmap

所以我试图使用android图形位图来调整图像大小。代码中没有错误,但是当我构建项目时,它会抛出" System.NotSupportedException:不知道Android.Graphics.Bitmap"异常。

我尝试勾选公共语言运行时异常并重建项目都没有用。

这是我的代码

 [Activity(MainLauncher = false, Theme = "@style/MyTheme")]
   public class Duzenle_Activity : ActionBarActivity
  {
    public static ListView liw;
    Intent intent = new Intent();

    public Dialog dialog;
    public static int toplam_hesap_tutucu;
    public static Duzenle_Adapter adapt;
    public static TextView toplam;
    private BackgroundWorker bw = new BackgroundWorker();
    public static int toplam_hesap = 0;
    public List<Sepet> gecici_sepet;
    List<Yemek_Liste> yemek_ = new List<Yemek_Liste>();


    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.menu_duzenle);
        var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
        SetSupportActionBar(toolbar);
        SupportActionBar.Title = "Duzenle";
        yemek_ = MainActivity.db.selectItem();

        liw = FindViewById<ListView>(Resource.Id.listv_duzenle);
        adapt = new Duzenle_Adapter(this, Resource.Layout.duzenle_model, yemek_,this);
        liw.Adapter = adapt;

        var toolbarBottom = FindViewById<Toolbar>(Resource.Id.toolbar_bottom_duzenle);
        toolbarBottom.InflateMenu(Resource.Menu.ekle_action);
        toolbarBottom.MenuItemClick += (sender, e) =>
        {

            if (e.Item.TitleFormatted.ToString() == "Ekle")
            {
                var transaction = FragmentManager.BeginTransaction();
                var dialogFragment = new Dialog_Ekle(this);

                dialogFragment.Show(transaction, "dialog_fragment");

            }

        };
        }
    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        if (resultCode == Result.Ok)
        {

            Duzenle_Adapter adapter = ((Duzenle_Adapter)liw.Adapter);
            Bitmap mBitmap = null;
            mBitmap = Android.Provider.MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data);


            Bitmap originalImage = BitmapFactory.DecodeByteArray(mBitmap.ToArray<Byte>(), 0, mBitmap.ByteCount);
            Bitmap resizedImage = Bitmap.CreateScaledBitmap(originalImage, 25, 25, false);
            adapter.al_getir().adresler = resizedImage;

            adapter.NotifyDataSetChanged();
            Console.WriteLine("ADRES1" + " " + data.Data);


        }
    }
    public void tikla()
    {
        var imageIntent = new Intent();
        imageIntent.SetType("image/*");
        imageIntent.SetAction(Intent.ActionGetContent);
        StartActivityForResult(
            Intent.CreateChooser(imageIntent, "Select photo"), 0);

    }
}

我从画廊收到的图像为uri。

编辑:为什么在代码中没有错误时抛出此异常。它实际上很奇怪。它不能关于android.graphics库吗?

编辑2:我将这些位图保存到数据库,然后在listview中显示

Bitmap a = sepet[position].adres;
            tut.img.SetImageBitmap(a);

1 个答案:

答案 0 :(得分:0)

根据我之前的说法,请试试:

 protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (resultCode == Result.Ok)
            {
                Duzenle_Adapter adapter = ((Duzenle_Adapter)listView1.Adapter);
                //adapter.SelectedYemek.ImageUri = data.Data;
                var mBitmap = Android.Provider.MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data);
                adapter.SelectedYemek.ImageBitmap = Bitmap.CreateScaledBitmap(mBitmap, 80, 80, false);
                adapter.NotifyDataSetChanged();
            }
        }