使用应用程序内部自己的相机拍摄图像时复制的图像

时间:2016-12-13 08:24:11

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

通过使用相机意图在我的应用程序中拍照,图像从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,另一张保存到图库。怎么解决呢?

1 个答案:

答案 0 :(得分:0)

我认为您希望图像保存在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);