我试图从相机捕获图像,压缩它,然后将其存储到SD卡.如果我使用下面的代码直接将其保存到SD卡,我会得到完整的图像.但是,如果我尝试在系统中加载图像,我会得到一个超小的图像大小,如320 x 240而不是完整的5 mp图像.
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT,getImageUri());
startActivityForResult(intent,CAMERA_PIC_REQUEST);
getImageURI()的位置
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;
}
现在,当我尝试将其保存到内部存储器时,我使用以下代码来获取微小的图像:
public void imageFromCamera() { //code to retrieve image
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent,CAMERA_PIC_REQUEST);
}
在我的startActivitForResult中我有以下内容:
@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());
}
}
最佳答案
在没有MediaStore.EXTRA_OUTPUT的情况下调用相机意图时,相机仅返回一个小缩略图,因为意图包不是为了传递大内存块而设计的.
从SDK文档for MediaStore:
原文链接:https://www.f2er.com/android/430478.html从SDK文档for MediaStore:
标准意图动作,可以发送给相机应用程序捕获图像并将其返回.
调用者可以传递额外的EXTRA_OUTPUT来控制该图像的写入位置.如果EXTRA_OUTPUT不存在,则在额外字段中返回小尺寸图像作为Bitmap对象.这对于只需要小图像的应用程序非常有用.如果存在EXTRA_OUTPUT,则将将全尺寸图像写入EXTRA_OUTPUT的Uri值.