我的代码可以正常工作,但是从相机上我得到的图像质量真的很差。我需要它们具有更好的质量,因为我想稍后将它们全屏显示。 我正在使用SDK版本21 +
private void takePhoto() {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
结果活动:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 0:
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
} catch (IOException e) {
e.printStackTrace();
}
saveBitmap(bitmap);
......
break;
}
我在这里保存它:
public void saveBitmap(Bitmap bitmap){
String timeStamp = new SimpleDateFormat("dd-MM-yyyy_HHmmss").format(new Date());
ContextWrapper wrapper = new ContextWrapper(getBaseContext());
File file = wrapper.getDir("Images",MODE_PRIVATE);
file = new File(file, timeStamp+".jpg");
try{
OutputStream stream = null;
stream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
stream.flush();
stream.close();
}catch (IOException e)
{
e.printStackTrace();
}
Uri savedImageURI = Uri.parse(file.getAbsolutePath());
PathFromCamera = savedImageURI.getEncodedPath();
}
此后,我将 PathFromCamera 用作路径。
imageView.setImageBitmap(BitmapFactory.decodeFile(PathFromCamera));