如何从Android上的Camera选择的图像中获得正确的宽度和高度? [英] How do i get right width and height from image picked by Camera on Android?
本文介绍了如何从Android上的Camera选择的图像中获得正确的宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要执行以下操作:
- 使用Android相机拍照...
- 从图像中删除背景并放入另一个背景中
- 保存
我正在做这3个步骤...
问题是图像以小尺寸(160 x 120)保存。
当我从相机获得结果时,我这样做:
Im doing those 3 steps fine... The problem is the image is saved in a small size (160 x 120). When i get the result from camera i do this:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
Log.i("Test", "Width: " + photo.getWidth() + " Height: " + photo.getHeight());
返回
Width: 160 Height: 120
我从数据获取的图像变量是1280 x 960 ......
The image that I am getting from "data" variable is 1280 x 960...
如果我使用
background= Bitmap.createScaledBitmap(background, 1280, 960, false);
我得到的图像质量差......
The image I get as bad quality...
如何获得正确尺寸的位图?!
How can I get the bitmap in the right size?!
推荐答案
尝试将图像写入文件并然后返回文件名作为结果:
Try writing out the image to a file and then returning the filename as the result:
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = new File(filename);
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (Exception e) {
}
Intent intent = this.getIntent();
intent.putExtra("filename", filename);
this.setResult(RESULT_OK, intent);
finish();
}
这篇关于如何从Android上的Camera选择的图像中获得正确的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文