设置为imageview后,位图质量较差 [英] bitmap bad quality after set to 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
.然后,使用图像加载库,例如
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
.
Here is a sample app that demonstrates using EXTRA_OUTPUT
.
这篇关于设置为imageview后,位图质量较差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!