gpt4 book ai didi

Android:SkImageDecoder::Factory 返回 null

转载 作者:IT老高 更新时间:2023-10-28 21:53:47 24 4
gpt4 key购买 nike

我正在使用我的本地主机来获取图像并在 ImageView 中查看。出于某种原因,我收到了 Factory 返回的 null 错误。我已经多次查看代码,但我看不出有什么问题。任何帮助将不胜感激!

GalleryZoom.java

public class Zoom extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.gallery_zoom);

String selection = getIntent().getExtras().getString("image");
Toast.makeText(this, selection, Toast.LENGTH_LONG).show();

new backgroundLoader().execute();
}


private class backgroundLoader extends AsyncTask<Void, Void, Void> {
Bitmap bmp;

@Override
protected Void doInBackground(Void... params) {

bmp = DecodeBitmapSampleSize(getIntent().getExtras().getString("image"), 48, 64);
return null;
}

@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);

ImageView image = (ImageView) findViewById(R.id.imageZoom);
image.setImageBitmap(bmp);
}

}

public Bitmap DecodeBitmapSampleSize (String strURL, int reqWidth, int reqHeight) {
InputStream in = null;
Bitmap bmp = null;

in = OpenHttpConnection(strURL);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(in, null, options);

options.inSampleSize = calculateSampleSize(options, reqWidth, reqHeight);

options.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeStream(in, null, options);
return bmp;
}

private InputStream OpenHttpConnection(String strURL) {

try {
URL url = new URL(strURL);

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(connection.getInputStream());
return in;
} catch (Exception exception) {
exception.printStackTrace();
return null;
}
}

public static int calculateSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {

final int width = options.outWidth;
final int height = options.outHeight;
int inSampleSize = 1;

if (width > reqWidth || height > reqHeight) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) reqHeight);
} else {
inSampleSize = Math.round((float) width / (float) reqWidth);
}
}
return inSampleSize;
}

}

LogCat 日志

08-13 21:55:19.578: I/MemoryCache(3197): MemoryCache maximum limit is 6MB
08-13 21:55:19.658: I/MemoryCache(3197): cache size = 24600, length = 1
08-13 21:55:19.688: I/MemoryCache(3197): cache size = 24600, length = 1
08-13 21:55:19.708: I/MemoryCache(3197): cache size = 24600, length = 1
08-13 21:55:19.708: I/MemoryCache(3197): cache size = 24600, length = 1
08-13 21:55:20.628: I/MemoryCache(3197): cache size = 71600, length = 2
08-13 21:55:20.678: I/MemoryCache(3197): cache size = 101408, length = 3
08-13 21:55:26.228: I/MemoryCache(3197): MemoryCache maximum limit is 6MB
08-13 21:55:26.228: I/MemoryCache(3197): MemoryCache maximum limit is 6MB
08-13 21:55:26.998: D/skia(3197): --- SkImageDecoder::Factory returned null

最佳答案

我也遇到了同样的问题。而且我确保下载图像的 url 是正确的。通过调试代码,我发现第一次解码后inputstream中的位置变量设置为1024。所以我在第二次解码之前添加了 inputstream.reset() 。这样可行。希望可以帮助别人。

关于Android:SkImageDecoder::Factory 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12006785/

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