2012-02-06 3 views
0

作成したフォルダに自分の写真を実際のサイズで保存します。このために私はたくさんのコードを試しましたが、実際のサイズでギャラリーに保存されたすべての写真ですが、私の場所にこの写真を保存すると写真が圧縮されました。 その後、ギャラリーから自分のフォルダに写真をコピーして、実際のサイズの写真を取得しようとしました。この場合、写真はコッピングしていますが、実際のサイズではありません。再び圧縮されます。今、私は私のフォルダに私のイメージ・フォームのギャラリーをコピーAndroid:実際のサイズで作成したフォルダに画像を保存する方法

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); 
    } 

onActivityResult方法でその後

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(
      Intent.createChooser(cameraIntent, "Select Picture"), 
      CAMERA_REQUEST); 

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) {} 


    } 

ここに写真をコピーしているカメラを開くための 私のフォルダには圧縮されるまで。

答えて

0

use cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);ここでoutputFile Uriは、保存するファイルの場所です。

+0

以前このコードを使用しましたが、このコードでは写真を圧縮形式で保存しています。 –

+0

正確にはわかりませんが、cameraIntent.putExtra(MediaStore.EXTRA_QUALITY、1)のようなものがあるはずです.1は高画質、0は低画質です。しかし確かではありません。一度それをチェックしてください –

+0

ここに私のEclipseは "EXTRA_QUALITYは解決できないか、フィールドではありません"と表示します。 EXTRA_VIDEO_QUALITYは動画のためのものです。 –

関連する問題