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


请协助!

最佳答案

经过数小时的噩梦,我得以使用以下代码征服:

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


它可能会帮助某人。

关于java - Android SkImageDecoder::Factory在解码图像时返回null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31836176/

10-12 06:12