开发者

Background of the Image created from Bitmap

开发者 https://www.devze.com 2023-04-09 13:28 出处:网络
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.

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 bac开发者_JAVA技巧kground 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:

Background of the Image created from Bitmap

After the bitmap is written to the file system the image is as below:

Background of the Image created from Bitmap

Could some one kindly help me with this. I would like me image to have the same background as the canvas. Thanks in advance.


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号