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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:54:43+00:00 2026-06-04T12:54:43+00:00

I have my SurfaceView up and running with a button to open the camera

  • 0

I have my SurfaceView up and running with a button to open the camera and take a picture which is used as the background and another button to add items that sit on top and can be moved around. This all works fine until I try to save the SurfaceView as a Bitmap when all I get is the background and none of the images on top.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if(_mGotImage){

        canvas.drawBitmap(_mImage, 0, 0, null);
    }else{

            canvas.drawColor(Color.BLACK);
    }

    //if the array is not empty
    if(!_mJazzItems.isEmpty()){

        //step through each item in the array
        for(JazzItem item: _mJazzItems){

            //get the bitmap it is using
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), item.getBitmap());
            //and draw that bitmap at its X and Y coords
            canvas.drawBitmap(bitmap, item.getX(), item.getY(), null);

        }
    }
}

This is the method called to try and save the Canvas.

    public void screenGrab(){

    Bitmap image = Bitmap.createBitmap(_mPanelWidth, _mPanelHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(image);
    this.onDraw(canvas);

    String path=Environment.getExternalStorageDirectory() + "/test2.png";
    File file = new File(path);

    try{

        file.createNewFile();
        FileOutputStream ostream = new FileOutputStream(file);
        image.compress(CompressFormat.PNG, 100, ostream);
        ostream.flush();
        ostream.close();

    }catch (Exception e){

        e.printStackTrace();
    }
}

The onDraw works fine, I get my camera shot in the background and can add all my items over the top and move them around. Just when I try to get a screen shot, none of the items on top are present.

Thanks for any help!!

— UPDATE —

I have modified the screen grab method to this:

    public void screenGrab(){

    Bitmap image = Bitmap.createBitmap(_mPanelWidth, _mPanelHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(image);

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

    //if the array is not empty
    if(!_mJazzItems.isEmpty()){

        //step through each item in the array
        for(JazzItem item: _mJazzItems){

            //get the bitmap it is using
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), item.getBitmap());
            //and draw that bitmap at its X and Y coords
            canvas.drawBitmap(bitmap, item.getX(), item.getY(), null);

        }
    }

    String path=Environment.getExternalStorageDirectory() + "/test2.png";
    File file = new File(path);

    try{

        file.createNewFile();
        FileOutputStream ostream = new FileOutputStream(file);
        image.compress(CompressFormat.PNG, 100, ostream);
        ostream.flush();
        ostream.close();

    }catch (Exception e){

        e.printStackTrace();
    }
}

I can’t see why this is not drawing the other images over the top…

  • 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-04T12:54:44+00:00Added an answer on June 4, 2026 at 12:54 pm

    in my case i am using this:

    public static Bitmap combineImages(Bitmap c, Bitmap overLayImage, Context con) {
        Bitmap cs = null;
        int width, height = 0;
        width     = c.getWidth();
        height     = c.getHeight();
        cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas comboImage = new Canvas(cs);
        comboImage.drawBitmap(c, 0, 0, null);
        String left = yourleftPosition;
        String top = yourtopPosition;
    
        comboImage.drawBitmap(overLayImage, Float.parseFloat(left), Float.parseFloat(top),null);
        /******
        *
        * Write file to SDCard
        *
        * ****/
        String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png";
        OutputStream os = null;
        try {
            String pathis = Environment.getExternalStorageDirectory()
            + "/DCIM/Camera/" + tmpImg;
            os = new FileOutputStream(pathis);
            cs.compress(CompressFormat.PNG, 100, os);
        }
        catch (IOException e) {
            Log.e("combineImages", "problem combining images", e);
        }
        return cs;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SurfaceView that is resposible for drawing a Bitmap as a background
I have a game which has surfaceview and running on a thread. if I
I have a SurfaceView that is being used to draw images, and I would
I have a surfaceview which is displaying a camera preview I have it taking
In my application, I have a SurfaceView showing a Camera preview, and want to
I have two Activities, both have an inner class SurfaceView, which has an inner
I currently have a SurfaceView that is in Landscape mode. Currently I am trying
I have an Application in that I want to capture video using Surfaceview and
I have a dialog box which appears on top of a SurfaceView. I would
I have a SurfaceView which is currently drawing a series of Bitmaps. These bitmaps

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.