解码我的位图时遇到问题。这是我的代码:
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解决方案。只有我哥特才能提出申请。
答案 0 :(得分:0)
尝试此代码
byte[] byteimage = file.toByteArray(); // I dont know whether toByteArray() will work
// or not Some how convert your file into byte[]
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap rebitmap = BitmapFactory.decodeByteArray(byteimage,0,byteimage.length, opt);
return rebitmap;