在安卓开发中,如果对拍照后的图片进行图片裁剪,如果是调用系统的裁剪,如下:
private void cropPhoto() {
Intent intent = new Intent("com.android.camera.action.CROP");
Uri uri = Uri.parse("file://" + picSavePath);
intent.setDataAndType(uri, "image
private void cropPhotoAndZoom() {
Intent intent = new Intent("com.android.camera.action.CROP");
Uri uri = Uri.parse("file://" + picSavePath);
intent.setDataAndType(uri, "image
public static Bitmap toBigZoom(String path, float x, float y) {
Log.e("bitmaputil", "path---" + path + "--x--y--" + x + "--" + y);
Bitmap bitmap = BitmapFactory.decodeFile(path);
if (bitmap != null) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
float sx = 0;
float sy = 0;
if ((float) w / h >= 1) {
sx = (float) y / w;
sy = (float) x / h;
Log.e("bitmaputil---", "w/h--->=1");
} else {
sx = (float) x / w;
sy = (float) y / h;
Log.e("bitmaputil---", "w/h---<1");
}
Matrix matrix = new Matrix();
matrix.postScale(sx, sy); // 长和宽放大缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
Log.e("bitmaputil---", "w---" + resizeBmp.getWidth() + "h--" + resizeBmp.getHeight());
return resizeBmp;
}
return null;
}
2中代码,通过判断裁剪框的w,h比来设置图片是放大是横向放大,还是竖向放大,放大后的效果基本上能满足需求。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



