Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8846323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:57:17+00:00 2026-06-14T11:57:17+00:00

My question is how to handle an Out of Memory error when decoding a

  • 0

My question is how to handle an Out of Memory error when decoding a byte array into a bitmap so I can do a rotation on it. My code is as follows and before you say its a duplicate, I have tried using BitmapFactory.Options and setting the sample size to 2. However the quality loss was far too bad to be acceptable. Also it appears to only be happening on one device so maybe its a one off thing, however I’m inclined to believe if it affects one, there will be 25 more like it later. Also this is happening on the FIRST photo taken and this is the only work that this activity does with regards to bitmaps. And while I’m working in Monodroid, Java answers are welcome too as I can usually translate them to C# fairly easily.

public void GotImage(byte[] image)
    {
        try
        {
            Android.Graphics.Bitmap thePicture = Android.Graphics.BitmapFactory.DecodeByteArray(image, 0, image.Length);
            Array.Clear(image, 0, image.Length);
            image = null;
            GC.Collect();
            Android.Graphics.Matrix m = new Android.Graphics.Matrix();
            m.PostRotate(90);
            Android.Graphics.Bitmap rotatedPicture = Android.Graphics.Bitmap.CreateBitmap(thePicture, 0, 0, thePicture.Width, thePicture.Height, m, true);
            thePicture.Dispose();
            thePicture = null;
            GC.Collect();

            using (MemoryStream ms = new MemoryStream())
            {
                rotatedPicture.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, ms);
                image = ms.ToArray();
            }
            rotatedPicture.Dispose();
            rotatedPicture = null;
            GC.Collect();

            listOfImages.Add(image);
            storeButton.Text = "  Store " + listOfImages.Count + " Pages  ";
            storeButton.Enabled = true;
            takePicButton.Enabled = true;
            gotImage = false;
            cameraPreviewArea.camera.StartPreview();
        }
        catch (Exception ex)
        {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
            alertDialog.SetTitle("Error Taking Picture");
            alertDialog.SetMessage(ex.ToString());
            alertDialog.SetPositiveButton("OK", delegate { });
            alertDialog.Show();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:57:18+00:00Added an answer on June 14, 2026 at 11:57 am

    Well after a long day of learning, I discovered a fix/workaround. This involved setting the resolution of the picture being taken by the camera before the picture was taken instead of trying to scale it after the fact. I also set the option in settings for the user to try different resolutions till they get one that works best for them.

    Camera.Parameters parameters = camera.GetParameters();
    parameters.SetPictureSize(parameters.SupportedPictureSizes[parameters.SupportedPictureSizes.Count - 1].Width,
                        parameters.SupportedPictureSizes[parameters.SupportedPictureSizes.Count - 1].Height);
    camera.SetParameters(parameters);
    camera.StartPreview();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to question Java Appengine APPSTATS causing java out of memory error
QUESTION: How can I handle potential contention between two separate threads accessing the same
just a general question, do you ALWAYS have to handle error? i was just
My question is eerily similar to Writing a generic class to handle built-in types
I have a question regarding using Semaphores HANDLE WINAPI CreateSemaphore(...); Is there anyway I
General question about java servlets and the best way to handle requests. If I
UPDATED QUESTION Since the ctor is not supported by .NETCF (public FileStream(IntPtr handle, FileAccess
I have a UI question that troubled me on the best method to handle
A very simple question, if i create a HANDLE in app1.exe and it gets
Very noob question, I know, but I didn't manage to handle real-time slider move

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.