我在解码我的位图时遇到问题。这是我的代码:
public static Bitmap loadujSmallBitmapeczke(File file) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
options.inSampleSize=4;
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(file.getAbsolutePath(), options);
}
在这里我用来从 sd 卡获取图像:
public class ServiceImages1 extends LinearLayout{
public ServiceImages1(Context context, String id) {
super(context);
init(id);
}
public ServiceImages1(Context context, AttributeSet attrs, String id) {
super(context, attrs);
init(id);
}
private void init(String id) {
File file;
file = new File("/sdcard/DinEgen/"+id);
ImageView imageView = new ImageView(getContext());
//imageView.setImageURI(Uri.fromFile(file));
imageView.setImageBitmap(HejSokolyLadujBMP.loadujSmallBitmapeczke(file));
addView(imageView);
}
}
其中 id 是我的图像的名称。
我得到错误:decoder->decode returned false
。我该如何解决这个问题?问题出在哪里?
编辑:我的图片在 sd 卡上,所以我不能使用带有 URL 的解决方案。只有我得到的是文件路径。