gpt4 book ai didi

java - Android SkImageDecoder::Factory 在解码图像时返回 null

转载 作者:行者123 更新时间:2023-11-30 10:59:39 25 4
gpt4 key购买 nike

这是一种解码图像的方法。调用时,它会抛出 SkImageDecoder::Factory 并返回 null。

private static Bitmap decodeFile(File f) {
try {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BufferedInputStream buffer=new BufferedInputStream(new FileInputStream(f));
BitmapFactory.decodeStream(buffer, null, o);
try {
buffer.reset();
}
catch (IOException e) {
e.printStackTrace();
}

// The new size we want to scale to
final int REQUIRED_SIZE=70;

// Find the correct scale value. It should be the power of 2.
int scale = 1;
while(o.outWidth / scale / 2 >= REQUIRED_SIZE &&
o.outHeight / scale / 2 >= REQUIRED_SIZE) {
scale *= 2;
}

BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
// o2.inJustDecodeBounds = false;
//buffer.close();

return BitmapFactory.decodeStream(buffer, null, o2);
}
catch (FileNotFoundException e) {}
return null;
}
}

请帮忙!

最佳答案

经过几个小时的噩梦,我能够使用以下代码征服:

if(file.exists()) {
System.out.println("!!!!!!!!!!!!!!!!>>>>>>>>>>>>> About entering the decode file");
Options var7 = new Options();
var7.inPreferredConfig = Config.ARGB_8888;
this.bmp = BitmapFactory.decodeFile(this.file.getAbsolutePath(), var7);
System.out.println(this.file.getAbsolutePath()+" <<<<<<<<<I AM HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +
"!!!!!!!!!!!!!!!" + this.file.toString());
}else{
Toast.makeText(getApplicationContext(), "Wrong Capture please try again!", Toast.LENGTH_LONG).show();
System.out.println("!!!!!!!!!!!!!!!!!!!!!!>>>> FILE1 FAILED");
}

它可能对某人有帮助。

关于java - Android SkImageDecoder::Factory 在解码图像时返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31836176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com