im trying to save the image i get from the gallery to my bitmap but it keeps giving me a System.NullReferenceException: 'Object reference not set to an instance of an object.' error. it works if i save it from taking a picture from my camera. if anyone knows how to fix the problem i'd be more than happy if you can help <3
private void GalleryAction(object sender, DialogClickEventArgs e) { Intent intent = new Intent(); intent.SetType("image/*"); intent.SetAction(Intent.ActionGetContent); StartActivityForResult(intent,1); } private void CameraAction(object sender, DialogClickEventArgs e) { Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture); StartActivityForResult(intent, 0); } protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 0)//coming from camera { if (resultCode == Result.Ok) { bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); iv.SetImageBitmap(bitmap); } } else if(requestCode == 1) //coming from gallery { if (resultCode == Result.Ok) { bitmap = (Android.Graphics.Bitmap)data.Extras.Get("image"); iv.SetImageBitmap(bitmap); } } }
Getand the(Bitmap)cast into separate lines to determine which is responsible for the null?