Android 如何从相机获取小尺寸图像?
我有方法调用camera activity,,但camera的结果是大尺寸的,我想将图像调整为小尺寸。这是我的方法Android 如何从相机获取小尺寸图像?,android,camera,size,Android,Camera,Size,我有方法调用camera activity,,但camera的结果是大尺寸的,我想将图像调整为小尺寸。这是我的方法 public void startCamera() { fileName =helper.getKdStore(c)+"_"+System.currentTimeMillis()+ ".jpg"; _path=Environment.getExternalStorageDirectory().toString() + "/Alfa Location/";
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();
}
}
}
如何调整图像大小??谢谢你你可以在使用相机发送后更改图像大小
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);
@akubabas你把它放在你做
Toast
的地方,其中imagePath
是你放在Intent
中的URI
(outputFileUri
,就像你在代码中所说的那样。你可能想把它变成一个类变量)。还有其他一些调整图像大小的好例子(例如:)。如果要显示图像或保存已调整大小的图像,请参见此处: