从图库中选择图像后图像质量不佳

时间:2014-05-01 19:08:03

标签: android

我用它来让用户从图库中选择一个图像:

Intent i = new Intent(
                        Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                i.setType("image/*");
                i.putExtra("crop", "true");
                i.putExtra("scale", true);
                i.putExtra("return-data", true);
                startActivityForResult(i, RESULT_LOAD_IMAGE);

然后它将显示在ImageView中:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {

            final Bundle extras = data.getExtras();
            Bitmap photo = extras.getParcelable("data");

            ImageView imageView = (ImageView) findViewById(R.id.image);
            imageView.setImageBitmap(photo);

        }
    }

它有效,但现在图片质量很差。 如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您不应指定任何额外内容,因为它们与设备有关。就这样做:

Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK)
    {
        Uri selectedImage = data.getData();
        //load Uri into ImageView
    }
}

如果您的应用是图像密集型,我会考虑使用像Picasso这样的库来加载图片,而不是仅仅执行imageView.setImageBitmap(photo)