0
내 사진을 실제 크기로 만든 폴더에 저장하고 싶습니다. 이것을 위해 많은 코드를 시도했지만 모든 경우 사진이 실제 크기로 갤러리에 저장되었지만이 사진을 내 위치에 저장하면 사진이 압축됩니다. 그 후 실제 크기의 사진을 얻기 위해 Gallery에서 내 폴더로 사진을 복사하려고했습니다. 이 경우 사진의 크기는 실제 크기와 다를 수 있습니다. 다시 압축됩니다. 카메라 여는 :에 그 후Android : 실제 크기로 만든 폴더에 이미지를 저장하는 방법
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(
Intent.createChooser(cameraIntent, "Select Picture"),
CAMERA_REQUEST);
을 onActivityResult를 방법 : 여기 사진
protected void copyImageFromGallery(Uri uri){
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String sourceImagePath= uri.toString();
File sdImageMainDirectory = new File(
Environment.getExternalStorageDirectory() + "/pix/images");
if (!sdImageMainDirectory.exists()) {
sdImageMainDirectory.mkdirs();
}
String destinationImagePath= Environment.getExternalStorageDirectory() + "/pix/images";
File source= new File(data, souceImagePath);
File destination= new File(sd, destinationImagePath);
if (source.exists()) {
FileChannel src = new FileInputStream(source).getChannel();
FileChannel dst = new FileOutputStream(destination).getChannel();
dst.transferFrom(src, 100, src.size());
src.close();
dst.close();
}
}} catch (Exception e) {}
}
을 복사한다 : 지금은 내 폴더 내 이미지 형태로 갤러리를 복사
try {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
if (photo != null) {
imageView.setImageBitmap(photo);
}
// Image name
final ContentResolver cr = getContentResolver();
final String[] p1 = new String[] {
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATE_TAKEN };
Cursor c1 = cr.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null,
null, p1[1] + " DESC");
if (c1.moveToFirst()) {
String uristringpic = "content://media/external/images/media/"
+ c1.getInt(0);
Uri newuri = Uri.parse(uristringpic);
// Log.i("TAG", "newuri "+newuri);
String snapName = getRealPathFromURI(newuri);
Uri u = Uri.parse(snapName);
File f = new File("" + u);
String fileName = f.getName();
editTextPhoto.setText(fileName);
checkSelectedItem = true;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(CompressFormat.PNG, 0 /* ignored for PNG */,
bos);
byte[] bitmapdata = bos.toByteArray();
// Storing Image in new folder
// StoreByteImage(mContext, bitmapdata, 100, fileName);
copyImageFromGallery(newuri);
// To appear images in created folder of Gallery dynamically
// as soon as they
// are captured.
sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
// Delete the image from the Gallery
getContentResolver().delete(newuri, null, null); // for delete
}
c1.close();
}
} catch (NullPointerException e) {
System.out.println("Error in creating Image." + e);
} catch (Exception e) {
System.out.println("Error in creating Image." + e);
}
내 폴더에 있지만 압축 전까지.
이전에이 코드를 사용했지만이 코드는 사진을 압축 된 형식으로 저장합니다. –
정확히 알지는 못하지만 cameraIntent.putExtra (MediaStore.EXTRA_QUALITY, 1)와 같은 것이 있어야한다고 생각합니다. 1은 고품질이고 낮은 품질은 0입니다. 그러나 확실하지 않다. 한 번 확인하십시오 –
여기 내 이클립스 쇼 "EXTRA_QUALITY 해결할 수 없거나 필드가 아닙니다". EXTRA_VIDEO_QUALITY는 동영상 용입니다. –