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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:05:05+00:00 2026-06-13T19:05:05+00:00

Im attempting to save the actual image from my applications resources to a file

  • 0

Im attempting to save the actual image from my applications resources to a file on the SD card so it is accessible by the messaging application but I’m getting the error of – The method write(byte[]) in the type FileOutputStream is not applicable for the arguments (Drawable) – where its supposed to save it. I believe that I’m not using the appropriate method to save the actual image itself and I’m having difficulty finding a solution.

                        // Selected image id
                int position = data.getExtras().getInt("id");
                ImageAdapter imageAdapter = new ImageAdapter(this);
                ChosenImageView.setImageResource(imageAdapter.mThumbIds[position]);
                Resources res = getResources();
                Drawable drawable = res.getDrawable(imageAdapter.mThumbIds[position]); //(imageAdapter.mThumbIds[position]) is the resource ID
                try {
                    File file = new File(dataFile, FILENAME);
                    file.mkdirs();
                    FileOutputStream fos = new FileOutputStream(file);
                    fos.write(drawable); // supposed to save the image here, getting the error at fos.write
                    fos.close();
                }catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
              }
            }
        }    
  • 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-13T19:05:06+00:00Added an answer on June 13, 2026 at 7:05 pm

    You error does explain it all, A fileOuputStream can not take a Drawable, it needs a byte array.

    So you need to get the bytes from your Drawable.

    try:

    Drawable drawable = res.getDrawable(imageAdapter.mThumbIds[position]);
    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] bitmapdata = stream.toByteArray();
    

    ….

    fos.write(bitmapdata);
    

    And while you are at it, put the fos.close() in the Finally bock

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

Sidebar

Related Questions

I am attempting to save recorded audio from an application to the storage device
So, I'm doing some image processing in MATLAB, and attempting to save a file
I'm opening an image from the gallery, resizing it, and attempting to save the
I am attempting to save a series of booleans in a settings.cs file. Here
To track user activity history on a web application, I am attempting to save
Im attempting to crop a pretty high res image and save the result to
I'm attempting to define an extremely simple utility method that will save me from
When attempting to save an account into an ACAccountStore, I sometimes receive this error.
I am attempting to save an array of longs as a text file using
I'm attempting to save a dataURL made from an HTML5 canvas to my mysql

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.