이 코드가 작동하므로 카메라를 열 때 "재시도"& "Ok"화면이 나타나는데 문제가되지 않지만 "재시도 "카메라가 촬영 모드로 돌아갈 때 (사진 찍기) 이미지가 여전히 비트 맵에로드되고 뒤 키를 눌러 카메라를 종료 할 때 이미지가 Dir에 저장됩니다.사용자가 "OK"를 선택한 경우에만 이미지 저장
다시 시도를 클릭하고 카메라를 종료 할 때 이미지를 저장하지 않는 방법이 있습니까? 또는 "OK"를 선택할 때만 저장 하시겠습니까?
카메라 API를 사용하고 있습니다. ParaCamera 카메라 API에서 안드로이드 빌드를 사용해야합니까? 그렇다면 시간
public void takePhoto() {
checkStoragePermissions();
SharedPreferences unID = PreferenceManager.getDefaultSharedPreferences(getContext());
imgID = unID.getString("unique_ID", "");
camera = new Camera.Builder()
.resetToCorrectOrientation(true)
.setTakePhotoRequestCode(1)
.setDirectory("/Pictures/WasThere/Images")
.setName(imgID)
.setImageFormat(Camera.IMAGE_JPEG)
.setCompression(75)
.setImageHeight(700)
.build(this);
try {
camera.takePicture();
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == Camera.REQUEST_TAKE_PHOTO){
Bitmap bitmap = camera.getCameraBitmap();
if(bitmap != null) {
captureImage.setImageBitmap(bitmap);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// this makes the image disapear in 6 Seconds
captureImage.setImageResource(R.color.transpar);
}
},6000);
storeImage(bitmap);
}else{
Toast.makeText(getContext().getApplicationContext(),"Picture not taken!",Toast.LENGTH_SHORT).show();
}
}
}
private void storeImage(Bitmap image) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
Log.d(TAG,
"Error creating media file, check storage permissions: ");// e.getMessage());
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.JPEG, 75, fos);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
private File getOutputMediaFile(){
// To be safe, you should check that the SDCard is mounted
//captureImage.setImageBitmap(camera.getCameraBitmap());
File mediaStorageDir = new File(Environment.getExternalStorageDirectory().toString()
+ "/Pictures/WasThere");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.
// Create the storage directory if it does not exist
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("_dd_MM_yyyy_k:mm:ss").format(new Date());
File mediaFile;
String mImageName=imgID +timeStamp+".jpg";
mediaFile = new File(mediaStorageDir.getPath()+File.separator + mImageName);
//Gets the image current path
mCurrentPhotoPath = mediaFile.getAbsolutePath();
galleryAddPic();
return mediaFile;
}
핸들 로직의 resultCode를 기반으로하는 경우 현재 로직이 resultCode – VVB
@VVB와 관계없이 실행되기 때문에 도움말에 감사했습니다 !!!! –