【问题标题】:Android transparent images copied to gallery obtain solid black background复制到图库的Android透明图片获得纯黑色背景
【发布时间】:2013-02-09 15:35:51
【问题描述】:

我使用以下语句将图像从资产复制到图库应用,效果很好:

MediaStore.Images.Media.insertImage(getContentResolver(), myBitmap, myTitle ,  myDescription);

图像是具有透明背景的 png 文件。当我将它们从资产加载到 ImageView 时,它们会正确显示。

问题是,以前导入图像的透明背景在图库中变成了纯黑色。

png 是由 gimp 创建的 png24。我还尝试了 Apple 的预览应用程序添加的透明 gif 和具有透明度的 png,结果相同。

为什么会这样?

【问题讨论】:

  • 您是否尝试过使用文件路径参数的第二种方法?结果一样吗?
  • 是的,这里也一样。我还明确设置了支持 alpha 通道的格式:没有变化:BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap myBitmap = BitmapFactory.decodeFile(ctx.getFilesDir().getAbsolutePath()+java.io.File.separator+"locos"+"/BR03_1049.png", options); MediaStore.Images.Media.insertImage(ctx.getContentResolver(),myBitmap,"standardlok" , "ohne" );

标签: android png gallery android-imageview png-transparency


【解决方案1】:

我知道这是一个老问题,但我也遇到了同样的问题。问题是MediaStore.Images.Media.insertImage 存储的文件的 MIME_TYPE 为“image/jpeg”,而 jpeg 不支持透明度。

一种解决方案是制作您自己的使用另一种图像格式的内容提供商。 Picasso 图片库可能也值得一看。

【讨论】:

    猜你喜欢
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2013-03-20
    • 2011-09-24
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多