tags:

views:

519

answers:

1

hello..

i am getting an image from web server (which has transparent background).now i need to save this image on my sdcard and show it to user.but when i save the image to sdcard.. it saves with a black background..i need this image with background..

i hv tried following methods to save the image ---

Method 1:

Bitmap bitmap = BitmapFactory.decodeStream(is);
byte[] b;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 75, bytes);
b = bytes.toByteArray();
 try {
  File myFile = new File("/sdcard/" + image_id + ".jpg");
  myFile.createNewFile();
  OutputStream filoutputStream = new FileOutputStream(myFile);
  filoutputStream.write(b);
  filoutputStream.flush();
  filoutputStream.close();
        }catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    Log.d("file", "not created");
   }

Method 2:

MediaStore.Images.Media.insertImage(getContentResolver(),
   bitmap, "sample", "image/png");

plz help...

+4  A: 

Why don't you save the stream to a file? It is already encoded as a transparent image.

Quick note: JPEG doesn't support transparency.

Tughi