Android Save text with transparent background
I am trying to render text by creating a canvas for a bitmap and the textview is drawn on the canvas and it is saved as a PNG image. I have 3 channels that do not have a 4th channel. Now how can I add alpha to the bitmap.
Bitmap testB;
strLogoImagePath = "storage/sdcard0/as.png";
testB = Bitmap.createBitmap(objTextView.getWidth(), objTextView.getHeight(),Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(testB);
objTextView.layout(0, 0, objTextView.getWidth(), objTextView.getHeight());
objTextView.draw(c);
objTextView.setLayoutParams(rlLayoutParamsCanvas);
FileOutputStream stream = new FileOutputStream(strLogoImagePath);
testB.compress(CompressFormat.PNG, 100, stream);
testB.recycle();
stream.close();
+3
source to share
1 answer
Adding alpha to Bitmap
is done with BitmapDrawable
Save your method and just:
- Build
BitmapDrawable
from scratch or use this constructorBitmapDrawable(Bitmap bitmap)
to load an existing bitmap. - Then use
BitmapDrawable.setAlpha(int alpha)
.
I hope it solves your alpha problem.
+1
source to share