我有调用相机活动的方法,但相机的结果是大尺寸,我想将图像调整到小尺寸..这是我的方法
public void startCamera()
{
fileName =helper.getKdStore(c)+"_"+System.currentTimeMillis()+ ".jpg";
_path=Environment.getExternalStorageDirectory().toString() + "/Alfa Location/";
file = new File(_path, fileName);
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, IMAGE_CAPTURE);
}
这是活动结果方法
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == IMAGE_CAPTURE)
{
if (resultCode == RESULT_OK)
{
Log.d("ANDRO_CAMERA","Picture taken!!!");
//imageView.setImageURI(imageUri);
Toast.makeText(Detail.this, "Gambar Berhasil di simpan", Toast.LENGTH_LONG).show();
}
}
}
我如何调整图片大小?谢谢
答案 0 :(得分:2)
您可以使用
从相机提供后更改图像尺寸int desiredImageWidth = 100; // pixels
int desiredImageHeight = 100; // pixels
BitmapFactory.Options o = new BitmapFactory.Options();
Bitmap newImage = Bitmap.createScaleBitmap(BitmapFactory.decodeFile(imagePath, o),
desiredImageWidth,
desiredImageHeight,
false);