【问题标题】:PNG image display from SD card of AndroidAndroid SD卡的PNG图像显示
【发布时间】:2011-06-20 15:34:44
【问题描述】:

我在 SD 卡中保存了一个透明的 PNG 图像。我想显示的是现在。我为此使用了以下代码。

selected_photo = (ImageView) findViewById(R.id.selected_photo);
Uri photoUri = Uri.parse(photoPath);
                        selected_photo.setImageBitmap(MediaStore.Images.Media.getBitmap(getContentResolver(),photoUri));

但它在显示中给出了不透明的图像。如何在不丢失透明度的情况下显示PNG图像?

【问题讨论】:

    标签: android image png transparency sd-card


    【解决方案1】:

    MediaStore API 可能会丢弃 alpha 通道(即解码为 RGB565)。如果你有文件路径,直接使用 BitmapFactory,但告诉它使用保留 alpha 的格式:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);
    selected_photo.setImageBitmap(bitmap);
    

    【讨论】:

      猜你喜欢
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多