Android:SkipageDecoder::工厂返回null

Android:SkipageDecoder::工厂返回null,android,Android,我正在使用本地主机获取图像并在ImageView中查看。由于某种原因,我得到工厂返回的空错误。我已经看过代码很多次了,但我不知道出了什么问题。任何帮助都将不胜感激 GalleryZoom.java public class Zoom extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState)

我正在使用本地主机获取图像并在ImageView中查看。由于某种原因,我得到工厂返回的空错误。我已经看过代码很多次了,但我不知道出了什么问题。任何帮助都将不胜感激

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;
    }

}

我也遇到了同样的问题。我还要确保url是正确的,可以下载图片。通过调试代码,我发现inputstream中的位置变量在第一次解码后被设置为1024。 因此,我在第二次解码之前添加了inputstream.reset()。这很有效。
希望可以帮助其他人。

从gallery应用程序返回的意图中读取流时,我遇到了类似的问题。正如Shellum上面提到的,inputstream.reset()抛出一个IOException,所以我通过关闭流并再次打开它来解决它。简单,成功了。

环顾四周后,我找到了最佳解决方案

正如#jia George所指出的,您应该在第一次解码后重置inputstream,问题是不支持一些时间重置,但您可以将inputstream封装在BufferedInputStream中,而这一个就可以了

final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; 
BufferedInputStream buffer=new BufferedInputStream(is);
BitmapFactory.decodeStream(buffer,null,options);
buffer.reset();

    // Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,reqHeight);

    // Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false; 
BitmapFactory.decodeStream(buffer,null,options);

这可能是一种罕见的情况,但对于使用URL的用户来说,如果您尝试从URL加载图像,但URL未引用图像,则会看到此错误

例如:

而不是:

如上所述,使用毕加索确保您的url正确,只需将开发程序中的链接复制并粘贴到web浏览器中即可

我键入:

而不是


这对我很有效,但请确保首先调用
boolean supported=inputStream.markSupported()
。必须支持标记,否则reset()将引发
IOException
。如果不支持,可以打开第二个输入流。您是如何解决这个问题的?我遇到了同样的问题,我已经在这里发布了:。由于某些原因,它在一些非常特定的网站和文件上不起作用。请参阅这篇为我工作的帖子:[[1]:我遵循了这个建议,将流位置设置为0(在C#中)。此外,一些URL可能以
.jpg
.png
.tif
等结尾,但实际上并不引用图像。例如:。
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; 
BufferedInputStream buffer=new BufferedInputStream(is);
BitmapFactory.decodeStream(buffer,null,options);
buffer.reset();

    // Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,reqHeight);

    // Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false; 
BitmapFactory.decodeStream(buffer,null,options);