从URI加载的图像具有黑色背景

时间:2017-04-03 12:08:54

标签: android

我正在尝试加载具有透明背景的PNG。

mImageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                ImageThumbnailAdapter.IMAGE_PROJECTION, null, null,
                MediaStore.Images.ImageColumns.DISPLAY_NAME);

投影:

public static final int IMAGE_ID_COLUMN = 0;
    public static final int IMAGE_NAME_COLUMN = 1;

加载方法:

private static Bitmap loadThumbnail(ContentResolver cr, Uri uri) {
    return MediaStore.Images.Thumbnails.getThumbnail(
            cr, ContentUris.parseId(uri), MediaStore.Images.Thumbnails.MINI_KIND, sBitmapOptions);
}

在视图中设置:

            Bitmap bitmapOld = loadThumbnail(mArgs.mContentResolver, mArgs.mUri);

            ByteArrayOutputStream out = new ByteArrayOutputStream();

            bitmapOld.compress(Bitmap.CompressFormat.PNG, 100, out  );
            final Bitmap bitmap = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));

            Bitmap mutableBitmap = bitmapOld.copy(Bitmap.Config.ARGB_8888, true);
            final Canvas canvas = new Canvas(mutableBitmap);

//          Canvas c = new Canvas(bitmap);
            canvas.drawColor(0, PorterDuff.Mode.CLEAR);

//This drawabl is coming black in Background. 
                final Bitmap bmpfinal = mutableBitmap;

2 个答案:

答案 0 :(得分:0)

使用此代码

return MediaStore.Images.Media.getBitmap(context.getContentResolver‌​(), uri);

我希望它可以解决你的问题...

答案 1 :(得分:0)

Picasso将帮助您解决问题,浏览提供的链接并整合毕加索。