在android系统编程方式创建一个透明图像 [英] create a transparent image programmatically in android
本文介绍了在android系统编程方式创建一个透明图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到来自Web服务器的映像(具有透明背景)。现在我需要保存在我的SD卡这一形象,并显示它user.but当我将图像保存到SD卡。 。这样可以节省搭配黑色background..i需要背景这一形象。
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..
我HV尝试以下方法保存图像---
i hv tried following methods to save the image ---
方法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");
}
方法2:
MediaStore.Images.Media.insertImage(getContentResolver(),
bitmap, "sample", "image/png");
plz帮助...
plz help...
推荐答案
你为什么不救流文件?这已经是EN codeD作为透明的形象。
Why don't you save the stream to a file? It is already encoded as a transparent image.
快速注:JPEG不支持透明度
Quick note: JPEG doesn't support transparency.
这篇关于在android系统编程方式创建一个透明图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文