Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

crash with java.lang.Outofmemoryerror. Help!

$
0
0

i have followed the tutorial "Take a Picture and Save Using Camera App"
i now have my app setup to try multi photos. so when i take 4 picture with the camera its then add each picture to imageView1, imageView2, imageView3, & imageView4. when i take the 4th picture and press OK within android camera app i get java.lang.outofmemoryrror at this line of code "App.bitmap = App._file.Path.LoadAndResizeBitmap (width, height);" i think it has something to with BitmapHelper.cs used to resize the image.

i have tried app.bitmap.dispose();
app.bitmap = null;
app.bitmap.recycle();
still get error.

also to note: my app starts out using 15mb of system memory after the first photo is add to imageview1 the app memory usage increases to 32 mb and so on. always doubling in the power of two it seems.

here is my code im getting the error on:

                            imageView iimageView1 = FindViewById<ImageView>(Resource.Id.imageView1);
                ImageView iimageView2 = FindViewById<ImageView>(Resource.Id.imageView2);
                ImageView iimageView3 = FindViewById<ImageView>(Resource.Id.imageView3);
                ImageView iimageView4 = FindViewById<ImageView>(Resource.Id.imageView4);


                // display in ImageView. We will resize the bitmap to fit the display
                // Loading the full sized image will consume to much memory
                // and cause the application to crash.
                if (resultCode == Android.App.Result.Ok) {
                    if (iimageView1.Drawable == null) {

                        //App.bitmap = App._file.Path.LoadAndResizeBitmap;
                        int height = Resources.DisplayMetrics.HeightPixels;
                        int width = iimageView1.Height;
                        App.bitmap = App._file.Path.LoadAndResizeBitmap (width, height);
                        iimageView1.SetImageBitmap (App.bitmap);
                        //Uri tempuri = getImageUri (getAp);
                        //mediaScanIntent.Dispose();
                        pathtext.Text = App._file.ToString ();
                        //App.bitmap.Dispose();
                        //iimageView1.DestroyDrawingCache();
                        //App.bitmap.Dispose ();
                        //App.bitmap.Recycle();
                        //App.bitmap = null;

                        if (IsThereAnAppToTakePictures ()) {
                            TakeAPicture1 ();
                        }

                    } else if (iimageView2.Drawable == null) {
                        int height = Resources.DisplayMetrics.HeightPixels;
                        int width = iimageView2.Height;
                        App.bitmap = App._file.Path.LoadAndResizeBitmap (width, height);
                        iimageView2.SetImageBitmap (App.bitmap);
                        //Uri tempuri = getImageUri (getAp);
                        iimageView2.DestroyDrawingCache();
                        //App.bitmap.Dispose ();
                        //App.bitmap = null;
                    //  App.bitmap.Recycle();
                        pathtext2.Text = App._file.ToString ();
                        if (IsThereAnAppToTakePictures ()) {
                            TakeAPicture1 ();
                        }
                    }
                    else if (iimageView3.Drawable == null){
                        int height = Resources.DisplayMetrics.HeightPixels;
                        int width = iimageView3.Height;
                        App.bitmap = App._file.Path.LoadAndResizeBitmap (width, height);
                        iimageView3.SetImageBitmap (App.bitmap);
                        //Uri tempuri = getImageUri (getAp);
                        //App.bitmap.Dispose ();
                        //App.bitmap = null;
                    //  App.bitmap.Recycle();
                        pathtext3.Text = App._file.ToString ();
                        if (IsThereAnAppToTakePictures ()) {
                            TakeAPicture1 ();
                        }

                    }
                    else if (iimageView4.Drawable == null){
                        int height = Resources.DisplayMetrics.HeightPixels;
                        int width = iimageView4.Height;
//this is the line i get the error at!
                        App.bitmap = App._file.Path.LoadAndResizeBitmap (width, height);
                        iimageView4.SetImageBitmap (App.bitmap);
                        //Uri tempuri = getImageUri (getAp);
                        //App.bitmap.Dispose ();
                        //App.bitmap = null;
                    //  App.bitmap.Recycle();
                        pathtext4.Text = App._file.ToString ();
                        if (IsThereAnAppToTakePictures ()) {
                            TakeAPicture1 ();
                        }
                                }

i have looked and google but i'm just stuck in the mud.
c# has an easy when disposing of images but it only works with picturebox control.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>