Skip to content Skip to sidebar Skip to footer

How To Paint On Image And Save That Image In To Android?

I am new to canvas. I want to use the My already saved Image and want some paint on that image. after that i want to save it. I know that with using Canvas it is possible. I can ab

Solution 1:

Your problem is your drawing over and over on your entire canvas:

finalCanvasc=newCanvas (mBitmap); // creates a new canvas with your image is painted background
 c.drawColor(0, PorterDuff.Mode.CLEAR); // this makes your whole Canvas transparent
 canvas.drawColor(Color.WHITE);  // this makes it all white on another canvas
 canvas.drawBitmap (mBitmap, 0,  0,null); // this draws your bitmap on another canvas

Use logic roughly like this:

@Overridepublicvoidrun() {

Canvasc=newCanvas(mBitmap);


/* Paint your things here, example: c.drawLine()... Beware c.drawColor will fill your canvas, so your bitmap will be cleared!!!*/
...

/* Now mBitmap will have both the original image & your painting */Stringpath= Environment.getExternalStorageDirectory().toString(); // this is the sd cardOutputStreamfOut=null;
Filefile=newFile(path, "MyImage.jpg");
fOut = newFileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
}

Also don't forget to add necessary permission to save your file:

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />

outside <application></application> in your manifest file.

Post a Comment for "How To Paint On Image And Save That Image In To Android?"