现在我正在创建一个示例库应用程序。在此应用程序中,我从资产文件夹加载图像。当我使用ImageView显示这些图像时,我的logcat中出现了FAILED BINDER TRANSACTION错误。我有6个图像集,只有一个图像有这个问题。我的代码是,
从资源文件夹中加载图片,
final Bitmap[] mBitArray = new Bitmap[6];
try {
mBitArray[0] = getBitmapFromAsset("images/test_image.jpg");
mBitArray[1] = getBitmapFromAsset("images/gallery_img02.jpg");
mBitArray[2] = getBitmapFromAsset("images/gallery_img04.jpg");
mBitArray[3] = getBitmapFromAsset("images/gallery_img05.jpg");
mBitArray[4] = getBitmapFromAsset("images/gallery_img06.jpg");
mBitArray[5] = getBitmapFromAsset("images/gallery_img07.jpg");
} catch (IOException e) {
System.out.println("Inside the Exception");
}
位图转换代码,
private Bitmap getBitmapFromAsset(String strName) throws IOException {
AssetManager assetManager = getAssets();
InputStream istr = assetManager.open(strName);
Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}
我搜索了这个问题,我得到了以下解决方案,当我申请时,但它不会工作,
public static Bitmap scaleDownBitmap(Bitmap photo, int newHeight, Context context) {
final float densityMultiplier = context.getResources().getDisplayMetrics().density;
int h= (int) (newHeight*densityMultiplier);
int w= (int) (h * photo.getWidth()/((double) photo.getHeight()));
photo=Bitmap.createScaledBitmap(photo, w, h, true);
return photo;
}
答案 0 :(得分:3)
您是否已阅读此链接,它可能会帮助您找到解决方案。他们对这个错误进行了非常好的讨论:
https://groups.google.com/forum/#!topic/android-developers/KKEyW6XdDvg/discussion