0

こんにちは仲間のプログラマー。私の問題: 写真を作成するたびに、Android は自動的に 160x160px に縮小します。どうしてか分かりません。これが私のコードです:

ここで、カメラのすべての設定を行います。

public void ChosenPhoto(String extra) {
        String gallery = "gallery";
        String camera = "camera";

        if (extra.equals(gallery)) {
            Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            intent.setType("image/*");
            intent.putExtra("crop", "true");
            intent.putExtra("return-data", true);
            intent.putExtra("aspectX", 560);
            intent.putExtra("aspectY", 560);
            intent.putExtra("outputX", 560);
            intent.putExtra("outputY", 560);
            intent.putExtra("noFaceDetection", true);
            intent.putExtra("screenOrientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
            startActivityForResult(intent, PICK_FROM_GALLERY);
        } else if (extra.equals(camera)) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            intent.putExtra("crop", "true");
            intent.putExtra("aspectX", 560);
            intent.putExtra("aspectY", 560);
            intent.putExtra("outputX", 560);
            intent.putExtra("outputY", 560);
            intent.putExtra("noFaceDetection", true);
            intent.putExtra("screenOrientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            intent.putExtra("return-data", true);
            startActivityForResult(intent, PICK_FROM_CAMERA);
        }

}

ここで、後で使用します。

Bundle extras = data.getExtras();

                    photoBit = extras.getParcelable("data");
                    ByteArrayOutputStream PhotoStream = new ByteArrayOutputStream();
                    photoBit.compress(Bitmap.CompressFormat.PNG, 100, PhotoStream);
                    photos = PhotoStream.toByteArray();
                    Log.e(TAG, "Width:" + photoBit.getWidth() );

                    ImageView.setImageBitmap(photoBit);

ImageView では、後で縮小されていることがわかります。より正確に言うと、毎回 160x160px に...理由がわかりません。

私を助けてください。さらに詳しい情報が必要な場合は、お尋ねください。

4

1 に答える 1

2

「データ」で返されるのは、実際にはサムネイルのみであり、フルサイズの写真ではありません。この方法でフルサイズの画像を取得することはできませんが、カメラが画像を保存するファイルを作成する必要があります。説明付きの実例は、http://developer.android.com/training/camera/photobasics.htmlのタイトル「フルサイズの写真を保存」の下にあります。

まず、画像を保存する新しいファイルを作成する必要があります。ファイル名が他のファイルと衝突しないことを確認したい場合があります (タイムスタンプを追加)。

File file = new File(context.getExternalFilesDir( null ), "photo.jpg");

次に、インテントでこれを指定します。

intent.putExtra( MediaStore.EXTRA_OUTPUT, Uri.fromFile( file ) );
activity.startActivityForResult( intent, REQUEST_TAKE_PHOTO );

onActivityResult() では、写真が実際に撮影されたかどうかを確認します。イメージを持つ前に作成したファイル インスタンスを使用します。

if ( ( requestCode == REQUEST_TAKE_PHOTO ) && ( resultCode == RESULT_OK ) ) {

ファイルの画像を ImageView に入れたい場合は、次のようにします。

Bitmap bmp = BitmapFactory.decodeFile( file.getAbsolutePath() );
imageView.setImageBitmap(bmp);
于 2016-01-22T21:31:26.607 に答える