在安卓开发中,如果对拍照后的图片进行图片裁剪,如果是调用系统的裁剪,如下: private void cropPhoto() { Intent intent =
在安卓开发中,如果对拍照后的图片进行图片裁剪,如果是调用系统的裁剪,如下:
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比来设置图片是放大是横向放大,还是竖向放大,放大后的效果基本上能满足需求。
--结束END--
本文标题: android调用原生图片裁剪后图片尺寸缩放的解决方法
本文链接: https://www.lsjlt.com/news/28368.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0