【问题标题】:Images duplicated when take image using own camera inside app在应用程序内使用自己的相机拍摄图像时重复的图像
【发布时间】:2016-12-13 08:24:11
【问题描述】:

通过使用相机意图在我的应用中拍照,图像从 SD 卡和图库中复制。这是我的拍照代码:

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            // Ensure that there's a camera activity to handle the intent
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = "file to /storage/emulated/0/Pictures/folder/image.jpg"
                } catch (IOException ex) {
                    // Error occurred while creating the File
                    Log.e("Can't create file", ex.getLocalizedMessage());
                }

                Uri photoUri = Uri.fromFile(photoFile);

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
                    startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);

                }

图像保存到photoFile,另一个相同的图像保存到图库。如何解决?

【问题讨论】:

    标签: android android-intent camera android-camera-intent


    【解决方案1】:

    我假设您希望图像保存在 SD 卡中而不是图库中?如果是这样,请尝试将照片保存在设备外部存储器中应用程序的私人空间中,而不是公共图片目录中。我在我的应用程序中这样做了:

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File photoFile = File.createTempFile(imageFileName, ".jpg", storageDir);
    

    【讨论】:

    • 这没有帮助!我有同样的方法。它仍然会在“图片”文件夹中生成重复文件。我不明白为什么有些设备有这个问题,而不是全部。我们专门提供了在那里存储图像的路径,而 Android 正在存储重复的图像:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 2016-02-13
    • 2011-07-15
    相关资源
    最近更新 更多