Android: add bitmap to images.

I am inserting an image using InsertImage , but every time the image is stored on the SD card, its background turns to black. How do I remove this black background?

My code:

> Bitmap Img = BitmapFactory.decodeResource(getResources(),
>              R.drawable.ic_launcher); String path =
> Images.Media.insertImage(getContentResolver(), Img, "myImg", "Image");

      

+3


source to share


1 answer


use this format before saving images to SD card ----- โ†’> Bitmap.CompressFormat.PNG, if you are using Bitmap.CompressFormat.JPEG your problem will repeat



public class SDCard {

public void setBitmap(Bitmap bitmap, String filename)
        throws FileNotFoundException {

    File folder = new File(Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/JANU");

    if (!folder.exists()) {
        folder.mkdir();

    }
    File imagefile = new File(folder, filename);
    FileOutputStream fout = new FileOutputStream(imagefile);

    boolean bit = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fout);

}

      

+2


source







All Articles