Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android保存图像两次_Android - Fatal编程技术网

Android保存图像两次

Android保存图像两次,android,Android,我正在用编程的方式为我的几张照片做一个截图,但不知怎么的,图像保存在/TestProject/文件夹中,但也保存在普通图片文件夹中。有人知道为什么会这样吗。(安卓的普通图片文件夹会同时显示所有图片吗?) insertImage()方法还为插入的图像创建缩略图。您很可能看到缩略图和插入的图像 如果要通过媒体存储强制扫描图像,则应改用scanFile()[0]方法 [0] OutputStream out; root.setDrawingCacheEnabled(true); Bi

我正在用编程的方式为我的几张照片做一个截图,但不知怎么的,图像保存在/TestProject/文件夹中,但也保存在普通图片文件夹中。有人知道为什么会这样吗。(安卓的普通图片文件夹会同时显示所有图片吗?)

insertImage()
方法还为插入的图像创建缩略图。您很可能看到缩略图和插入的图像

如果要通过媒体存储强制扫描图像,则应改用
scanFile()
[0]方法

[0]

OutputStream out;

    root.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(root.getDrawingCache());
    root.setDrawingCacheEnabled(false);


    /* Preparation ==================================== */
    // Find the SD Card path
    File path = Environment.getExternalStorageDirectory();

    // Create a new folder in SD Card
    File dir = new File(path.getAbsolutePath() + "/TestProject/");
    dir.mkdirs();
    /* ================================================= */

    // Create a name for the saved image
    File file = new File(dir, (new Date().getTime() + ".jpg"));

    try {
        out = new FileOutputStream(file);

        // Compress into png format image from 0% - 100%
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
        MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, (new Date().getTime() + ".jpg"), null);

        Toast.makeText(this, "Farm art saved", Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        e.printStackTrace();
    }