设置为 imageview 后位图质量不佳 [英] bitmap bad quality after set to imageview

查看:16
本文介绍了设置为 imageview 后位图质量不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个为用户打开相机的应用程序,在捕获图像后,它将显示在 ImageView 上!但是 ImageView 中的图像质量很差
这是代码:

I am creating a app that opens camera for user and after image captured it will be shows on ImageView! But the image in ImageView has very bad quality
here is the code:

public class Camera extends AppCompatActivity implements View.OnClickListener {

ImageView imgView;
Button camera, setBackground;

Intent i;

int cameraData = 0;

Bitmap bitmap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.camera);
    initialize();
}

private void initialize() {
    imgView = (ImageView) findViewById(R.id.bPicture);
    camera = (Button) findViewById(R.id.bOpenCamera);
    setBackground = (Button) findViewById(R.id.bSetBackground);

    camera.setOnClickListener(this);
    setBackground.setOnClickListener(this);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        bitmap = (Bitmap) extras.get("data");

        Bitmap resizedBmp = Bitmap.createScaledBitmap(bitmap, imgView.getWidth(),imgView.getHeight(), false);
        imgView.setImageBitmap(resizedBmp);
    }
}

@Override
public void onClick(View v) {
    switch(v.getId()){
        case R.id.bOpenCamera:
            i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(i, cameraData);
            break;
        case R.id.bSetBackground:
            try {
                WallpaperManager wallmngr = WallpaperManager.getInstance(this);
                wallmngr.setBitmap(bitmap);
            } catch (IOException e) {
                e.printStackTrace();
            }
            break;
    }
}

}

我应该怎么做才能提高图像质量?

what should I do to increase image quality?

推荐答案

使用缩略图以外的其他内容.引用 ACTION_IMAGE_CAPTURE 的文档, 强调:

Use something other than the thumbnail. Quoting the documentation for ACTION_IMAGE_CAPTURE, with emphasis added:

调用者可能会传递一个额外的 EXTRA_OUTPUT 来控制这个图像的写入位置.如果 EXTRA_OUTPUT 不存在,则在额外字段中将小尺寸图像作为位图对象返回.这对于只需要小图像的应用程序很有用.如果存在 EXTRA_OUTPUT,则全尺寸图像将写入 EXTRA_OUTPUT 的 Uri 值.

The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

因此,在 EXTRA_OUTPUT 中指定一个 Uri,其中应写入完整的相机图像.然后,使用图像加载库,例如Picasso,将照片加载到您的 ImageView.

So, specify a Uri in EXTRA_OUTPUT where a full camera image should be written to. Then, use an image-loading library, like Picasso, to load the photo into your ImageView.

这是一个示例应用,演示了使用 EXTRA_OUTPUT.

这篇关于设置为 imageview 后位图质量不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆