Reputation: 1873
I am trying to create a signature component where the user can write his signature on the view and the resulting bitmap being saved as an image. I am able to achieve this successfully. But my issue is that the background color is of the image being saved is always transparent. In my onDraw method i do the following:
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.GREEN);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
and while writing to the file system i do the following:
fOut = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG,100, fOut);
fOut.flush();
fOut.close();
The view on the device while capturing the signature is as shown in the image below:
After the bitmap is written to the file system the image is as below:
Could some one kindly help me with this. I would like me image to have the same background as the canvas. Thanks in advance.
Upvotes: 1
Views: 171
Reputation: 20319
From your question it seems like you want to save the entire view as a bitmap instead of the path object. To do this you can simply save the DrawingCache
of the view as a Bitmap
.
myView.buildDrawingCache()
Bitmapt b = myView.getDrawingCache()
fOut = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG,100, fOut);
fOut.flush();
fOut.close();
Upvotes: 1