extractThumbnail生成未知的位图配置错误

时间:2015-11-24 14:43:31

标签: android image-manipulation

我尝试使用以下方法生成图像资源的缩略图:

Category 3

但是当我这样做时,我收到错误:

Dim LR1 As Long

With Sheets("Auto Lease Data")
   LR1 = .Range("A" & .Rows.Count).End(xlUp).Row

   With .Range("A" & LR1 & ":ZZ" & LR1)
       .AutoFill Destination:=.Range("A1:ZZ2"), Type:=xlFillDefault
    End With
End With

这是我的代码:

ThumbnailUtils.extractThumbnail(Bitmap src, int width, int height);

错误会在调用方法java.lang.IllegalArgumentException: unknown bitmap configuration 的行中弹出。

方法// get a scaled down version of the image resource, to avoid loading // the full image into memory Bitmap im1 = decodeSampledBitmapFromResource(context.getResources(), R.drawable.im1, R.dimen.thumbnail_width, R.dimen.thumbnail_height); Bitmap thumbnail = ThumbnailUtils.extractThumbnail(im1, R.dimen.thumbnail_width, R.dimen.thumbnail_height); holder.picture.setImageBitmap(thumbnail); 就是这里描述的方法: https://developer.android.com/intl/es/training/displaying-bitmaps/load-bitmap.html

图像是" JPEG"尺寸为680x1024,重183Ko的图像。

我试图改用方法:

extractThumbnail

但我得到同样的错误。

1 个答案:

答案 0 :(得分:4)

您可能遇到问题,因为您传递了资源的ID而不是ID代表的实际值。尝试添加

int height = (int)context.getResources().getDimension(R.dimen.thumbnail_height);
int width = (int)context.getResources().getDimension(R.dimen.thumbnail_width);

现在修改你的代码就像这样读。

// get a scaled down version of the image resource, to avoid loading
// the full image into memory
Bitmap im1 = decodeSampledBitmapFromResource(context.getResources(),
                R.drawable.im1, 
                width,
                height);

Bitmap thumbnail = ThumbnailUtils.extractThumbnail(im1,
                     width,
                     height);