P Srinivas Goud
P Srinivas Goud

Reputation: 896

How to save canvas drawing as image?

In my android app i am saving drawing as image.I am able to save the file but its not saving 100% perfectly i.e,some contents are missing spaces are coming. The function is below which is i am calling by onclick. Please Help me how to save perfect drawing for screen shots visit the following links: http://www.flickr.com/photos/77093196@N03/7066979339, http://www.flickr.com/photos/77093196@N03/7066979341

DigitalSignatureActivity.java

private DrawingSurface drawingSurface;

    // To save file as Image
        public void saveDrawing(View v) throws IOException {

            File mediaStorageDir = new File(
                    Environment
                            .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                    "MySignatures");
             Bitmap nBitmap = drawingSurface.getBitmap();
            try {
                if (!mediaStorageDir.exists()) {
                    mediaStorageDir.mkdirs();
                }
                String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                        .format(new Date());
                File mediaFile = new File(mediaStorageDir.getPath()
                        + File.separator + "SIGN_" + timeStamp + ".png");
             FileOutputStream out = new FileOutputStream(mediaFile);

            nBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
                out.flush();
                out.close();
                Toast.makeText(this, "Signature saved  to " + mediaFile,
                        Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), "Not saved",
                        Toast.LENGTH_SHORT).show();
            }

        }

DrawingSurface.java

public class DrawingSurface extends SurfaceView implements SurfaceHolder.Callback {
//some code
}

Upvotes: 1

Views: 1591

Answers (1)

P Srinivas Goud
P Srinivas Goud

Reputation: 896

I solved by setting canvas.drawColor(Color.WHITE, PorterDuff.Mode.DARKEN); in DrawingSurface.java class

Upvotes: 1

Related Questions