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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:12:07+00:00 2026-05-22T21:12:07+00:00

I need to create a bitmap from sdcard images so after getting uri of

  • 0

I need to create a bitmap from sdcard images so after getting uri of image i am getting byte data by opening inputStream as follows

public byte[] getBytesFromFile(InputStream is)
{
    byte[] data = null;
    ByteArrayOutputStream buffer=null;
    try
    {
        buffer = new ByteArrayOutputStream();

        int nRead;
        data = new byte[16384];
        while ((nRead = is.read(data, 0, data.length)) != -1)
        {
            buffer.write(data, 0, nRead);
        }

        buffer.flush();

        return buffer.toByteArray();
    } catch (IOException e)
    {
        return null;
    }
    finally
    {
        if(data!=null)
            data = null;
        if(is!=null)
            try {
                is.close();
            } catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if(buffer!=null)
            {
                try {
                    buffer.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                buffer = null;
            }
            System.gc();
    }

after this i am just creating bitmap of that data by following code

byte[] data = getBytesFromFile(is);
Bitmap bm= BitmapFactory.decodeByteArray(data, 0, data.length);

but it gives me outofmemory error. many peoples guide me to check for memory leakages but, this is the first step in my app., i mean thru intent filter i start my app from gallery menu option “share” which invokes my app with the image uri..
plz guide me guys if i am wrong… and also this exception comes on the devices which have high resolution images(size excceds 1MB), but any how it should create Bitmap…

  • 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-22T21:12:08+00:00Added an answer on May 22, 2026 at 9:12 pm

    Try to use the BitmapFactory.decodeStream() method instead of first loading the bytearray into memory. Also check out this question for more info on loading bitmaps.

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

Sidebar

Related Questions

Frequently we get image from server as byte stream, then we create Bitmap and
I need to create a binary bitmap from a closed 2D polygon represented as
I need to batch create images with text. Requirements: arbitrary size of bitmap PNG
I'm getting Image (actually instance of Bitmap class) from resources, and (to write it
I have a byte[]. It contains data of an image (jpeg or bitmap) with
In my activity, I create a Bitmap object and then I need to launch
I need to create a historical timeline starting from 1600's to the present day.
If I have a .Net Bitmap , I can create from it a GDI
I need to extract data from a third party system (I have no influence
I need to convert a PNG Image loaded from a file into an 8

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.