0

各位程序员好。我的问题:每次我制作照片时,Android 都会自动将其缩小到 160x160 像素。我不知道为什么。这是我的代码:

在这里,我设置了相机的所有首选项:

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() 中,您将检查照片是否实际拍摄。您将使用之前创建的 File 实例,现在有了图像。

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

如果要将文件中的图像放入 ImageView,可以这样做:

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