Save Bitmap with Alpha

Asked

Viewed 66 times

0

I have the following class:

public class TesteMultiImage extends ActionBarActivity {

Uri URI;
String ImagePath;
Button button;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_teste_multi_image);

        button = (Button)findViewById(R.id.button3);

        SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy_HHmm");
        final String currentDateandTime = sdf.format(new Date());
        final RelativeLayout rl = (RelativeLayout)findViewById(R.id.rl);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rl.buildDrawingCache();
                Bitmap bmap = rl.getDrawingCache();
                ImagePath = MediaStore.Images.Media.insertImage(
                        getContentResolver(),
                        bmap,
                        "banner" + currentDateandTime,
                        "banner"
                );

                URI = Uri.parse(ImagePath);

                Toast.makeText(getApplicationContext(), "Imagem Salva", Toast.LENGTH_LONG).show();
            }
        });
    }

}

It saves my relative layout as a bitmap. But she saves with a black background, and I need you to save with a transparent background. When trying to configure :

bmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

It doesn’t work. How to solve?

1 answer

0

The way :

ARGB_8888

It supports transparence, but initially the alpha channel is 'set' to opaque. You need to clear that pattern. Test the following :

Canvas c = new Canvas(bm);
c.drawColor(0, Mode.CLEAR);

Source (Stackoverflow)

  • I don’t know what you mean.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.