在android中以编程方式创建透明图像
我正在从web服务器(具有透明背景的)获取图像。现在我需要将此图像保存在SD卡上并向用户显示。但是当我将图像保存到SD卡时。。它以黑色背景保存..我需要有背景的图像 我尝试了以下方法来保存图像--- 方法1:在android中以编程方式创建透明图像,android,Android,我正在从web服务器(具有透明背景的)获取图像。现在我需要将此图像保存在SD卡上并向用户显示。但是当我将图像保存到SD卡时。。它以黑色背景保存..我需要有背景的图像 我尝试了以下方法来保存图像--- 方法1: Bitmap bitmap = BitmapFactory.decodeStream(is); byte[] b; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.Compr
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");
}
方法2:
MediaStore.Images.Media.insertImage(getContentResolver(),
bitmap, "sample", "image/png");
请帮助…为什么不将流保存到文件中?它已编码为透明图像 快速提示:JPEG不支持透明度