I am working on a project in which I have created a custom view with transparent background. Now I want to create an image of this view. I am using the below code to save and create an image from bitmap, but the generated image has black background and not transparent. I want transparent background. How can I achieve this?
view = suraVersesFragment.getMyView();
view.setBackgroundColor(Color.TRANSPARENT);
Bitmap b = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
view.draw(c);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.png");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}