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

时间:2015-08-05 15:03:43

标签: java android

这是一种解码图像的方法。调用时,它会抛出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;
    }
}

请帮助!

1 个答案:

答案 0 :(得分:1)

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

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

这可能有助于某人。

相关问题