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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:46:40+00:00 2026-05-23T20:46:40+00:00

as a many people i have a problem with big images too. ok,here my

  • 0

as a many people i have a problem with big images too.
ok,here my code. I found on stackoverflow how to fix this using BitmapFactory.Options. But in my situations i get image not from file. Can anyone tell me how to do this with Bitmap which already created in memory ( i get this picture from camera on phone)

 public void getImageAndSend( )
  {

     Bitmap newbmp ;
         newbmp= Bitmap.createBitmap(oBmp.getWidth(), oBmp.getHeight(),oBmp.getConfig());////<----------error here
      log("widt oBmp = "+oBmp.getWidth());/// width = 2048
      log(" height oBmp = "+oBmp.getHeight());///height 1538
      //BitmapFactory.Options options = new BitmapFactory.Options(); // <----- it's possible to do it without `BitmapFactory.decodeFile(pathToFile,options) ?? 
      //options.inTempStorage = new byte[16*1024];
          Canvas canvas = new Canvas(newbmp);
          //code 
  System.gc();/// can't right understand but this line fixed this problem on emulator but not on real device   

}

please tell me how to fix my problem ? : (
On emulator im not have this error. But on real device i see this error (bitmap size exceeds VM budget)
Regards, Peter.

  • 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-23T20:46:42+00:00Added an answer on May 23, 2026 at 8:46 pm

    since you are getting image from camera,get the uri of the image you capture in onActivityResult() method as follows

    Uri selectedImageUri=intent.getData();
    String actualPath=getRealPathFromURI(selectedImageUri);
    File file=new File(actualPath);
    Bitmap bitmap=decodeFile(file); //this is new bitmap which you can use for your purpose 
    
    public String getRealPathFromURI(Uri contentUri) {
            String[] proj = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(contentUri, proj, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
    
    
    private Bitmap decodeFile(File f){
            try {
                //Decode image size
                BitmapFactory.Options o = new BitmapFactory.Options();
                o.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(new FileInputStream(f),null,o);
    
                //The new size we want to scale to
                final int REQUIRED_SIZE=70;
    
                //Find the correct scale value. It should be the power of 2.
                int width_tmp=o.outWidth, height_tmp=o.outHeight;
                int scale=1;
                while(true){
                    if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
                        break;
                    width_tmp/=2;
                    height_tmp/=2;
                    scale*=2;
                }
    
                //Decode with inSampleSize
                BitmapFactory.Options o2 = new BitmapFactory.Options();
                o2.inSampleSize=scale;
                return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
            } catch (FileNotFoundException e) {}
            return null;
        }
    

    Hope this helps.This is the very familiar problem when u deal with high quality images taken from phone.check this out too

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

Sidebar

Related Questions

many people seem to have problem in making this work, so i am not
Many people have this same problem, but everyone's implementation is different. I need help
I try to google, but I can't fixed my problem. Many people have this
Seems to be a problem that many people have, but all the answers I
I have looked at many different peoples answers to this problem but they only
I have heard from many people that usage of templates make the code slow.
I have found many people with simliar issues but no soultions...basically I have two
I have refereed old questions and found that people face many issues after installing
I have a several questions about hibernate. In many questions here in stackoverflow, several
I am getting this message: SEVERE: Error loading WebappClassLoader . Many people have posted

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.