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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:25:21+00:00 2026-06-04T22:25:21+00:00

SOLUTION Thanks to @ChandraSekhar’s suggestions the issue was that I was passing in an

  • 0

SOLUTION

Thanks to @ChandraSekhar’s suggestions the issue was that I was passing in an Immutable Bitmap to the canvas constructor. The solution is to create a copy of it when using BitmapFactory.decodeFile();

Bitmap bmp = BitmapFactory.decodeFile(imageURL).copy(Bitmap.Config.ARGB_8888, true);

So I have a bitmap that I am using bitmapFactory.decodeFile() for and this works. I am able to create the bitmap, then I need to create a canvas and this is where things get weird.

Here’s the flow of what is happening.
I capture an image, then pass it to functionA that sizes it, and saves it out and returns its file path. ( I am using Phonegap Cordova )

I then pass that URL back to my java and use the previously saved image and manipulate it in functionB

CODE IN QUESTION:

// GET URL TO IMAGE
final JSONObject options = optionsArr.optJSONObject(0);
String imageURL = options.optString("image");

// create image bitmap
Bitmap bmp = BitmapFactory.decodeFile(imageURL);
bmp = Bitmap.createBitmap(bmp,0,0,655,655);

/* Everything works fine until this point */

// create image canvas
Canvas canvas = new Canvas(bmp);
Bitmap one = Bitmap.createBitmap(bmp);
canvas.drawBitmap(one,0,0,null);

I receive no errors, it just hangs. Here’s the kick in the pants – if I run another function say functionB first that one works but the other doesn’t.

I thought maybe I needed to flush and close my first FileOutputStream, but that didn’t seem to have any effect. I’ve tried different variable names for all elements, bitmaps, canvas, and fileoutputstreams.

here is an example of the full function…
NOTE: Because I am using phonegap / cordova I am returning a string

public String none(JSONArray optionsArr) {

    // SET FILE PATH
            String filePath = "";
            File path = new File(Environment.getExternalStorageDirectory()+"/myApp/");

            // TMP.jpg is where we store our temporary version of the image
            File NewFilePath = new File(path, "tmp_NBB.jpg");

            // CREATE FOLDERS IF NEEDED
            try{
                boolean success = false;

                if(!path.exists()){
                    success = path.mkdir();
                }
                if (!success){ 
                    Log.d("NONE","Folder not created.");
                }
                else{
                    Log.d("NONE","Folder created!");
                }
            }
            catch (Exception e){
                e.printStackTrace();
            }
            // GET URL TO IMAGE
                final JSONObject options = optionsArr.optJSONObject(0);
                String imageURL = options.optString("image");

                // create image bitmap
                Bitmap bmp = BitmapFactory.decodeFile(imageURL);
                bmp = Bitmap.createBitmap(bmp,0,0,655,655);

                // create image canvas
                Canvas canvas = new Canvas(bmp);
                Bitmap none = Bitmap.createBitmap(bmp);
                canvas.drawBitmap(none,0,0,null);

                // SAVE IMAGE
                try {
                    // OUTPUT STREAM
                    FileOutputStream out = new FileOutputStream(NewFilePath);
                    none.compress(Bitmap.CompressFormat.JPEG, 100, out);

                    // GET FILE PATH
                    Uri uri = Uri.fromFile(NewFilePath);
                    filePath = uri.toString();

                    try{
                        out.flush();
                        out.close();

                        // RETURN FILE PATH
                        return filePath;
                    }
                    catch (Exception e){
                        e.printStackTrace();
                    }


                } catch (Exception e) {
                    e.printStackTrace();
                }
            return filePath;
        }

Like I said this works for the first image, but when I attempt to open this image again, based on the returned filepath it chunks out at the create canvas line.

edit: The image path I am using looks like this:
/mtn/sdcard/myApp/tmp.jpg
thoughts?

  • 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-04T22:25:23+00:00Added an answer on June 4, 2026 at 10:25 pm
    Bitmap one = Bitmap.createBitmap(bmp);
    

    In the above code bmp is a Bitmap and you are creating another Bitmap object one from bmp.

    Remove that line and try by changing

    canvas.drawBitmap(one,0,0,null);
    

    to

    canvas.drawBitmap(bmp,0,0,null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

solution:[a-zA-Z0-9.!#$%&'*+-/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)* is a good choice I am using a regular expression like the below
SOLUTION Make sure in the plist that the storyboard name is listed as the
Here is the Solution ,thanks Gustavo for the suggestion: class Program { static void
I need to create a Windows service that works just like the task scheduler
Chosen Solution Thanks for the help everyone. I've decided to do the following. public
SOLUTION Thanks to 1111... vector<std::string> split_at_line(string str, int lines) { vector<std::string> nine_ln_strs; string temp;
Solution: Thanks to Shmiddty, I figured this out: $( static parent element ).on('submit', '#add_client',
(see my answer below for solution - thanks for the feedback) It's probably something
SOLUTION Thanks to casperOne's answer , here is my resulting function: Shared Function FormatDate(ByVal
SOLUTION: Thanks to Patrick below, I have refactored the C# CodeProject version into a

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.