从摄像头的Android拍摄照片,在一个非常小的尺寸 [英] android picture from camera being taken at a really small size
问题描述
我试着从相机,COM preSS它拍摄图像,然后将其存储到SD卡上。如果我直接用它正下方的code保存到SD卡上,我得到了完整的图像。但如果我尝试并加载图像系统中,我得到一个超小的图像大小,如320×240,而不是一个完整的500万像素的图像。
意向意图=新的意图(android.media.action.IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,getImageUri());
startActivityForResult(意向,CAMERA_PIC_REQUEST);
在这里getImageURI()是
私人乌里getImageUri(){
在DCIM //店面形象
文件=新的文件(Environment.getExternalStorageDirectory()+/DCIM","itshelp.jpg);
imgUri = Uri.fromFile(文件);
file.deleteOnExit();
Log.e(SYS,文件是在+ imgUri);
返回imgUri;
}
现在,当我尝试将其保存到内存中,而不是,我用下面的code,它让我的小图像:
公共无效imageFromCamera(){// code检索图像
意向意图=新的意图(android.media.action.IMAGE_CAPTURE);
startActivityForResult(意向,CAMERA_PIC_REQUEST);
}
和我startActivitForResult我有以下几点:
@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
super.onActivityResult(要求code,因此code,数据);
如果(要求code == CAMERA_PIC_REQUEST和放大器;&安培;结果code == RESULT_OK){
。位图BM =(位图)data.getExtras()获得(数据);
Log.e(SYS,宽度+ bm.getWidth()); //我在这里gettting一个非常小的宽度
OutputStream的outStream = NULL;
文件=新的文件(Environment.getExternalStorageDirectory()+/DCIM","itshelp.png);
尝试 {
outStream =新的FileOutputStream(文件);
bm.com preSS(Bitmap.Com pressFormat.JPEG,70,outStream);
outStream.flush();
outStream.close();
Log.i(中心,OK,图像保存到SD);
Log.i(中心,高度=+ bm.getHeight()+WIDTH =+ bm.getWidth());
}赶上(FileNotFoundException异常E){
e.printStackTrace();
Log.i(中心,FileNotFoundException异常:+ e.toString());
}赶上(IOException异常E){
e.printStackTrace();
Log.i(中心,IOException异常:+ e.toString());
}
}
当你调用无 MediaStore.EXTRA_OUTPUT
相机意图,相机返回只有一小,因为缩略图意图包的目的不是通过大内存块。
从SDK文档为MediaStore :
这可以被发送到具有相机应用程序捕捉图像并将其返回标准意图动作。
调用者可以通过一个额外的 EXTRA_OUTPUT
来控制,其中该图像将被写入。如果 EXTRA_OUTPUT
不是present,然后小尺寸图像返回作为额外字段Bitmap对象。这对于应用程序,只需要一个小的图像是有用的。如果 EXTRA_OUTPUT
是present,那么全尺寸图像将被写入 EXTRA_OUTPUT
的URI值
Im trying to capture an image from the camera, compress it, then store it to the SD card. If I directly save it to the SD card using the code directly below, I get the full image. But if i try and load the image in the system, i get a super small image size such as 320 by 240 instead of a full 5 mp image.
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri());
startActivityForResult(intent, CAMERA_PIC_REQUEST);
where getImageURI() is
private Uri getImageUri() {
// Store image in dcim
file = new File(Environment.getExternalStorageDirectory() + "/DCIM","itshelp.jpg");
imgUri = Uri.fromFile(file);
file.deleteOnExit();
Log.e("syS","file is at "+imgUri);
return imgUri;
}
Now when i try to save it to internal memory instead, I use the following code that gets me the tiny image:
public void imageFromCamera() { //code to retrieve image
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, CAMERA_PIC_REQUEST);
}
and in my startActivitForResult I have the following:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) {
Bitmap bm = (Bitmap) data.getExtras().get("data");
Log.e("sys", "width is "+bm.getWidth()); //im gettting an extremely small width here
OutputStream outStream = null;
file = new File(Environment.getExternalStorageDirectory() + "/DCIM","itshelp.png");
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.JPEG, 70, outStream);
outStream.flush();
outStream.close();
Log.i("Hub", "OK, Image Saved to SD");
Log.i("Hub", "height = "+ bm.getHeight() + ", width = " + bm.getWidth());
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i("Hub", "FileNotFoundException: "+ e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.i("Hub", "IOException: "+ e.toString());
}
}
When you call the camera intent without MediaStore.EXTRA_OUTPUT
, the camera returns only a small thumbnail since the intent bundle is not designed to pass large memory blocks.
From the SDK documentation for MediaStore:
Standard Intent action that can be sent to have the camera application capture an image and return it.
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
.
这篇关于从摄像头的Android拍摄照片,在一个非常小的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!