Android手机处理图片兼容性问题

Android图片处理整理总结:

1:Android拍照的时候我们会遇到一些状态,比如用三星手机拍照的话,有可能在拍完照片后,照片会自动旋转,下面这个方面是把旋转的照片还原回来:

Bitmap bitmap = BitmapFactory.decodeFile(Const.ACT_CREATE_PIC_PATH.concat(photoName));
int angle= imageUtils.getExifOrientation(Const.ACT_CREATE_PIC_PATH.concat(photoName));
if(angle!=0){ //如果照片出现了 旋转 那么 就更改旋转度数
Matrix matrix = new Matrix();
matrix.postRotate(angle);
bitmap = Bitmap.createBitmap(bitmap,0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}


2:如果Android应用需要处理和上传图片,那图片的大小是个大问题,因为主流的Android手机拍出的照片至少要3M以上,如果你的图片需要滤镜或者上传,那就会消耗很多时间。其实我们大多数时候是不需要质量那么高的图片的,图片分辨率高的时候只有在查看大图的时候有作用,在手机屏幕上查看图片不需要质量那么高的图片。所以,如果不需要裁剪的时候,可以自己等比例的减小图片的分辨率。示例代码:

public String scaleDown(String path,Context context)
{
Bitmap orignalB=BitmapFactory.decodeFile(path);
float ratio = Math.min((float) 974 / orignalB.getWidth(),(float) 974 / orignalB.getHeight());
int width = Math.round((float) ratio * orignalB.getWidth());
int height = Math.round((float) ratio * orignalB.getHeight());

Bitmap newB = Bitmap.createScaledBitmap(orignalB,width,height, true);
String imgName=path.substring(path.lastIndexOf("/")+1,path.length()-1);
String userId= UserHelper.getUserId(context);
String newpath=createDirectoryAndSaveFile(newB,userId+System.currentTimeMillis()+".jpg");
orignalB.recycle();
newB.recycle();
return newpath;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值