Android解析jpg

时间:2018-09-18 07:22:13

标签: android

我使用BitmapFactory加载相同的jpg图像,然后将其保存在本地,比较其二进制内容,发现Android 6.0和7.0的结果不同。为什么?

String path = Environment.getExternalStorageDirectory() + File.separator + "c_001.jpg";
File file = new File(path);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap srcBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
FileUtilTest.save(srcBitmap, "bitmap-create");

FileUtilTest.java

public static void save(Bitmap bitmap, String flag) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        String sdCardDir = Environment.getExternalStorageDirectory() + "/CoolImage/";
        File dirFile = new File(sdCardDir);
        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }
        File file = new File(sdCardDir, flag + "_" + System.currentTimeMillis() + ".png");
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
               if (out != null) {
                   out.close();
               }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

0 个答案:

没有答案