Java 为什么BitmapDecoder doesen';不行?
我正试图在互联网上下载一些图片,并用gridview将它们粘贴到屏幕上。。但是当我使用BitmapDecoder选项时,图像不会出现。。如果我不使用该选项(仅下载),屏幕上会显示图像:/Java 为什么BitmapDecoder doesen';不行?,java,android,url,bitmap,Java,Android,Url,Bitmap,我正试图在互联网上下载一些图片,并用gridview将它们粘贴到屏幕上。。但是当我使用BitmapDecoder选项时,图像不会出现。。如果我不使用该选项(仅下载),屏幕上会显示图像:/ URL url = new URL(src); Rect padding = new Rect(8,8,8,8); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput
URL url = new URL(src);
Rect padding = new Rect(8,8,8,8);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(input, padding , options);
options.inSampleSize = calculateInSampleSize(options, 300, 300);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(input, padding, options);
不能对同一输入流进行两次解码。最好的选择是立即将文件保存到磁盘并从磁盘解码,或者将输入流读入字节数组,然后解码字节数组。好,我更改代码并创建新的输入流。。现在的问题是:应用程序在虚拟机中运行,但在我的平板电脑中运行否:(