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 3425076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:33:03+00:00 2026-05-18T06:33:03+00:00

I need to take a picture with the camera and, if depending on the

  • 0

I need to take a picture with the camera and, if depending on the picture size, rotate it before saving it into the gallery.

I’m using

Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(imageCaptureIntent, IMAGE_CAPTURE);

To take the pic and save it to a temporary file.

Then

Bitmap bmp = BitmapFactory.decodeFile(imagePath);
String str = android.provider.MediaStore.Images.Media.insertImage(cr, bmp, name, description);

To save it.

This is the code i have tried to use to rotate the bitmap

Matrix matrix = new Matrix();
matrix.postRotate(180);
Bitmap x = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
android.provider.MediaStore.Images.Media.insertImage(cr, x, name, description);

The problem is I’m getting an OutOfMemoryException.

Is there a better way to handle the bitmaps to avoid breaking the memory?

~Thanks in advance, regards

  • 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-05-18T06:33:04+00:00Added an answer on May 18, 2026 at 6:33 am

    I don’t think there is a better way to handle bitmaps. You could try to parse data directly from a file as Byte[] a portion at a time, and manipulating it in pieces; it’s hard and you’ll probably end up with very ugly code.

    I also suggest the following:

    • Use android.provider.MediaStore.Images.Media.insertImage(cr, imagePath, name, description) instead of android.provider.MediaStore.Images.Media.insertImage(cr, bmp, name, description) this way there is no need to call Bitmap bmp = BitmapFactory.decodeFile(imagePath) and no bitmap will be loaded into memory at that point.

    • Throughout your code, make sure no bitmap is loaded unless needed. Set bitmaps that are no longer needed to null and call the garbage collector, or use bmp.recycle().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi stackoverflow friends, I need to take a picture using camera and after takin
I need to use the device camera to take a picture, save it into
I need to take a picture from a webcam into a webapp (PHP5/JQuery/HTML5) but
In my WP7 application I need to the user to take a picture before
I need to take an image and place it onto a new, generated white
I need to capture an image from a webcam (tethered camera, etc.) into a
So when I take pictures they get saved to DCIM/Camera/ directory. I need to
When I take picture with android, I call camera.TakePicture(shutterCallback, rawCallback, postCallback, jpegCallback); However I
Need to take a SELECT drop down list options and find if any of
i need to take some row. They came from sql TARIH (sql column) is

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.