저는 캔버스 드로잉을 취하여 외부 메모리에 저장하는 fragment
을 가지고 있습니다. USB를 연결하고 파일 디렉토리를 검색하여 장치에 들어갑니다. 나는 Android/data/appname/files/img/nameofimage.png
아래에 있습니다. 이제 카메라가 사진을 찍을 때 사진을 저장하는 두 번째 조각이 있지만 찾지 못합니다.Android : 카메라 사진을 잘못된 위치에 저장 하시겠습니까?
카메라
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check that request code matches ours:
if (requestCode == CALL_BACK) {
// Check if your application folder exists in the external storage,
// if not create it:
File imageStorageFolder = new File(
Environment.getExternalStorageDirectory() + File.separator
+ "Camera");
if (!imageStorageFolder.exists()) {
imageStorageFolder.mkdirs();
Log.d("FILE",
"Folder created at: " + imageStorageFolder.toString());
}
// Check if data in not null and extract the Bitmap:
if (data != null) {
String filename = "image";
String fileNameExtension = ".jpg";
File sdCard = Environment.getExternalStorageDirectory();
String imageStorageFolderName = File.separator + "Camera"
+ File.separator;
File destinationFile = new File(sdCard, imageStorageFolderName
+ filename + fileNameExtension);
Log.d("FILE", "the destination for image file is: "
+ destinationFile);
if (data.getExtras() != null) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
try {
FileOutputStream out = new FileOutputStream(
destinationFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
Log.e("FILE", "ERROR:" + e.toString());
}
}
}
}
}
캔버스
capSig.setView(sign = new Sign(this.getActivity(), null))
.setMessage(R.string.store_question)
.setPositiveButton(R.string.save,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
try {
sign.setDrawingCacheEnabled(true);
sign.getDrawingCache()
.compress(
Bitmap.CompressFormat.PNG,
10,
new FileOutputStream(
new File(
getActivity()
.getExternalFilesDir(
"img"),
"signature.png")));
} catch (Exception e) {
Log.e("Error ", e.toString());
}
온 클릭
private class ClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, CALL_BACK);
}
}
내가 완전히 일을 이해하지 못하는 전자 코드, 다른 위치에 저장하는 이유는 무엇입니까? 또한 Android/data/appname/files/Camera/
아래에 저장하려면 어떻게해야합니까?
편집 로그 캣이 나에게 말한다
는 여기에 저장되는 : 06-08 16 : 21 : 49.333 : D/FILE (4818) : 이미지 파일의 대상은 다음과 같습니다 /저장/에뮬레이션/0 /Camera/image.jpg 내가 생각하기에 파일에 비공개로 표시되어 있으므로 찾을 수 없습니다. 이것은 왜 여기에 저축되고 있는지 말해주지 않습니다.
2 편집
현재 코드
private class ClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File sdCard = Environment.getExternalStorageDirectory();
String path = sdCard.getAbsolutePath() + "/Camera" ;
File dir = new File(path);
if (!dir.exists()) {
if (dir.mkdirs()) {
}
}
String FileName = "image";
File file = new File(path, FileName + ".jpg");
Uri outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, CALL_BACK);
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check that request code matches ours:
if (requestCode == CALL_BACK) {
Log.v("RESULT", "Picture Taken");
}
}
그리고 저장되는 곳이 어디입니까? – MDMalik
@MDMalik 잘 카메라 하나가이 디렉토리에 저장됩니다 : /storage/emulated/0/Camera/image.jpg. 두 사람의 이름 지정 규칙에 큰 차이가없는 것 같습니다. 그래서 나는 그것이 왜 같은 장소에 저장하지 않는지 확실하지 않다 –