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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:04:56+00:00 2026-05-31T18:04:56+00:00

I’m making a simple drawing app on Android. I’m using the FingerPaint.java provided with

  • 0

I’m making a simple drawing app on Android. I’m using the FingerPaint.java provided with the ApiDemos sample as a base, adding some features and getting rid of others. It basically creates a canvas with a bitmap that you can draw on top.

I’ve added “open” and “save” features. The “save” feature stores the bitmap into a file using the getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) function, and the “open” feature launches startActivityForResult(photoPickerIntent, 1) and loads the selected image.

The problem is that I can’t draw on a bitmap that I’ve opened manually. A trace is shown when drawing with the finger, but once the finger is lifted from the screen the trace disappears. If I save this bitmap, it will show up completely unmodified in the gallery. But when starting the app, I can draw just fine on the canvas.

I’m pretty sure this is a very simple problem due to my lack of understanding of how Canvas and Bitmap work. Anyway, here’s my code.

When creating my custom view:

    public MyView(Context c){

        super(c);

        mBitmap = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);

    }

The OnDraw Override:

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(0xFFAAAAAA);
        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
        canvas.drawPath(mPath, mPaint);
    }

My “open” function:

    private void open(){
    //checkSD: 1 if read only, 2 if RW
    if(checkSD()==1 || checkSD()==2){
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, 1);
    }
}

And finally my onActivityResult:

    @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //RequestCode:1 image
    if (requestCode == 1) {
        if (resultCode == Activity.RESULT_OK) {
            Uri selectedImage = data.getData();
            try{
                InputStream fIn = getContentResolver().openInputStream(selectedImage);
                mBitmap = BitmapFactory.decodeStream(fIn);
                fIn.close();
            } catch (Exception e){
                e.printStackTrace();
            }

        }
    }
}

I think my error is in this code, but if anyone thinks it could be in the way I actually draw, I haven’t modified the touch_xxx and the onTouchEvent from the FingerPaint.java example, so you can take a look at it (or ask me to post it here if you can’t see it for some reason).

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-31T18:04:57+00:00Added an answer on May 31, 2026 at 6:04 pm

    Ok, solved it!

    I did 2 things. The first one was adding the following line right after “fIn.close();” inside onActivityResult:

    mCanvas = new Canvas(mBitmap);
    

    I’m still not quite sure why this is necessary but I know that it doesn’t work without this line.

    The 2nd thing I did was copying the bitmap I was loading. Turns out that BitmapFactory.decodeStream() returns an inmutable bitmap and in order to create a new canvas a mutable bitmap is needed. I found a good explanation in this blog post:

    http://sudarnimalan.blogspot.com.es/2011/09/android-convert-immutable-bitmap-into.html

    I used the second method, which is copying the bitmap into a new one, like this:

    mBitmap = mBitmap.copy(Config.ARGB_8888, true);
    

    I know from the post that this is not a safe method, but for now it works.

    If only I had used “inmutable bitmap” in my search I’d have come up with an answer by myself. Thank you anyways!

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.