2

所以我的问题正如标题所述。我正在下载许多不同的图像并缩放它们,然后将它们设置为视图。.gif我的问题是,在创建的视图中似乎只有图像可见,而应该包含.jpg图像的视图几乎是空白的。我说几乎是因为在每个不同形状的视图上似乎都有一个奇怪的小黑点,我所说.jpg的小是指一个周期的大小,所以这些可能是图像,但尺寸缩小了太多。任何帮助... ps 虽然输出,但我确信图像正在通过我的位图并进入 setImageBitmap()。

我的位图创建方法:

    @Override   
 protected Bitmap doInBackground(String... url) {

    String url1 = url[0];
    InputStream s = null;
    try {
        s = (new URL(url1)).openStream();
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    final BufferedInputStream is = new BufferedInputStream(s, 32*1024);

        try {
            final Options decodeBitmapOptions = new Options();
            // For further memory savings, you may want to consider using this option
            // decodeBitmapOptions.inPreferredConfig = Config.RGB_565; // Uses 2-bytes instead of default 4 per pixel

            if( parent.getResources().getDisplayMetrics().widthPixels >0) {
                final Options decodeBoundsOptions = new Options();
                decodeBoundsOptions.inJustDecodeBounds = true;
                is.mark(32*1024); // 32k is probably overkill, but 8k is insufficient for some jpgs
                BitmapFactory.decodeStream(is,null,decodeBoundsOptions);
                is.reset();
                final int originalWidth = decodeBoundsOptions.outWidth;
                final int originalHeight = decodeBoundsOptions.outHeight;
                Debug.out("Inbound image preview for : "+url1);
                Debug.out(originalWidth);
                Debug.out(originalHeight);
                // inSampleSize prefers multiples of 2, but we prefer to prioritize memory savings
                decodeBitmapOptions.inSampleSize= Math.max(1,Math.min(originalWidth / 2, originalHeight / 2));
            }

            return BitmapFactory.decodeStream(is,null,decodeBitmapOptions);
        } catch( IOException e ) {
            throw new RuntimeException(e); // this shouldn't happen
        } finally {
            try {
                is.close();
            } catch( IOException ignored ) {}
        }


    }

这里也是我下载后设置新图像的地方:

 protected void onPostExecute(Bitmap map) {
 //image is a object of type ImageView that has already been added to to the grand scheme of things
     image.setImageBitmap(map);
 }

我需要更新视图还是什么?如果是这样,为什么我的 gif 加载正常?

4

1 回答 1

0

问题出在我的缩放比例上,尤其是这条线decodeBitmapOptions.inSampleSize= Math.max(1,Math.min(originalWidth / 2, originalHeight / 2));

于 2013-05-18T07:03:14.343 回答