栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

android调用原生图片裁剪后图片尺寸缩放的解决方法

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

android调用原生图片裁剪后图片尺寸缩放的解决方法

在安卓开发中,如果对拍照后的图片进行图片裁剪,如果是调用系统的裁剪,如下:

 
 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比来设置图片是放大是横向放大,还是竖向放大,放大后的效果基本上能满足需求。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/159574.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号