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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:04:45+00:00 2026-05-24T08:04:45+00:00

I am using the following code to save/ load my picture OnCreate(){ super.onCreate(); setContentView(…)

  • 0

I am using the following code to save/ load my picture

 OnCreate(){
  super.onCreate();
  setContentView(...)
 ....
  setImage();   

  }
 protected void onResume(){
   super.onResume();
   setImage();  
   }


protected void onRestoreInstanceState(Bundle savedInstanceState){
   super.onRestoreInstanceState(savedInstanceState);
   setImage();

}

protected void onPostResume(){
   super.onPostResume();
   setImage();  

}

private void setImage(){
    if(loadPicture(getIntent().getStringExtra("position"),bitmap ) != null){
        Toast.makeText(this, "not null", Toast.LENGTH_SHORT).show();
          imageView.setImageBitmap(loadPicture(getIntent().getStringExtra("position"), bitmap));
    }
}
private void takePicture() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        File photo = new File(Environment.getExternalStorageDirectory(),
                "Pic.jpg");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    startActivityForResult(intent, 0);

}

private void savePicture(String filename, Bitmap b, Context ctx){
    try {
           ObjectOutputStream bos;
           FileOutputStream out;// = new FileOutputStream(filename);
           out = ctx.openFileOutput(filename, Context.MODE_WORLD_READABLE);
           bos = new ObjectOutputStream(out);
           b.compress(Bitmap.CompressFormat.PNG, 100, bos);
          if(b.compress(Bitmap.CompressFormat.PNG, 100, bos) == true)
              Toast.makeText(this, "returned true", Toast.LENGTH_LONG).show();

          bos.flush();
        //  bos.close();
          out.close();
    } catch (Exception e) {
           e.printStackTrace();
    }
}
private Bitmap loadPicture(String filename, Bitmap b){
    //Drawable myImage = null;
    try {
        FileInputStream fis = openFileInput(filename);
        ObjectInputStream bis = null;
        try {
            bis = new ObjectInputStream(fis);
        } catch (StreamCorruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        // myImage = Drawable.createFromStream(ois, filename);
         b = BitmapFactory.decodeStream(bis);
        try {
            //bis.close();
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    //return myImage;
    return b;

}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case 0:
        if (resultCode == Activity.RESULT_OK) {

            Uri selectedImage = imageUri;
            getContentResolver().notifyChange(selectedImage, null);

            ContentResolver cr = getContentResolver();

            try {
                bitmap = android.provider.MediaStore.Images.Media
                        .getBitmap(cr, selectedImage);

                imageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, bitmap.getHeight()/2, bitmap.getWidth()/2, false));
                //previos imageView.setImageBitmap(bitmap)
                savePicture(getIntent().getStringExtra("position"), bitmap,
                        getApplicationContext());

                Toast.makeText(this, selectedImage.toString(),
                        Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT)
                        .show();



            }

This works perfectly for saving the image in the emulator(the sample image, that is), but it doesn’t work in the real phone. After I take the image and press the ‘OK” icon on the phone, there is a blank screen for about 20 secs. and then it crashes.

  • 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-24T08:04:46+00:00Added an answer on May 24, 2026 at 8:04 am

    You should try some of the solutions provided here

    • Strange out of memory issue while loading an image to a Bitmap object
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to save images using the following code: - (void)writeData{ if(cacheFileName==nil) return;
I am using the following code to save and load images that I pick
I am using the following code to save an object and all its properties
I am using the following code to save values from a settings view that
I am using the following generic code to save entities. using (ITransaction tx =
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
I'm using the following code to create and load the xml in the isolated
I am using the following code to save a frame of a movie to
I am using following code to check whether a check box on my website
I am using following code to design my home page. The output (as shown

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.