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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:29:44+00:00 2026-05-18T09:29:44+00:00

I want to copy a picture from asstets folder and paste it in my

  • 0

I want to copy a picture from asstets folder and paste it in my package, just for test. but final image doesn’t show anything. when I want to open picture with paint, it says that “This is not a valid bitmap file”.

In my program, I start to read original image in this way:

private void copyImage()
{
    AssetManager am = getResources().getAssets();               
    try{
        image = BitmapFactory.decodeStream(am.open("tasnim.png"));
        imWidth  = image.getWidth();
        imHeight = image.getHeight();
    } 
    catch(IOException e){
        e.printStackTrace();
        System.out.println("Error accoured!");
    }
}

next, I’ll get pixels of image or extract pixels, and save pixels in array of integer (rgbstream).

private void getPixelsOfImage()
{
    rgbStream = new int[imWidth * imHeight];
    image.getPixels(rgbStream, 0, imWidth, 0, 0, imWidth, imHeight);
}

finally, I want to save it in my package,

private void createPicture()
{
    contextPath = context.getFilesDir().getAbsolutePath();
    String path = contextPath + "/" + picName;

    try{
        FileOutputStream fos = new FileOutputStream(path);
        DataOutputStream dos = new DataOutputStream(fos); 

        for(int i=0; i<rgbStream.length; i++)
            dos.writeByte(rgbStream[i]);

        dos.flush();
        dos.close();
        fos.close();
    }
    catch(IOException e){
        System.out.println("IOException : " + e);
    }
    System.out.println("Picture Created.");
}

Code works fine but result, nothing!!! 🙁
When I check DDMS it creates new file and store all pixels (because it shows the size of this file is 13300 and dimension of my original picture is 100*133). when I click “pull a file from the device” I can save it on my desktop. However, when I open it 🙂 nothing.

What you think? is there any problem in my code?
Thanks

  • 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-18T09:29:45+00:00Added an answer on May 18, 2026 at 9:29 am

    I don’t know what your intent is – do you want to write out a raw image file?

    Assuming that you want to write a JPEG or PNG or whatever, you can erase your entire code and do something a lot easier:

    Bitmap image = BitmapFactory.decodeStream(am.open("tasnim.png"));
    FileOutputStream fos = new FileOutputStream(path);
    image.compress(Bitmap.CompressFormat.PNG, 100, fos);
    

    With proper error checking of course.

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

Sidebar

Related Questions

I want to pick image from gallery and copy it in to other folder
i want copy pdf file from application path(/data/data/package name) to sdcard.for that i have
I'm loading an image from disk and want to copy (part of) it to
I want to copy a selection of lines from a file to another file
I want to copy directories and their subdirectories from C: to D: with same
I want to copy a xml file from one remote box to a bunch
I want to copy the contents of a DataGridView and paste it in Excel.
I have one image in a directory on my server, and want to copy
I want to copy pictures clicked by the user to the Data folder for
In my android application i want to copy the media images to another folder(in

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.