HM图片处理

 来源为HM某个老师的PPT,放在这里只为学习.
1. Load图形到内存
①.数码相机照片特别大3M以上,内存吃不消,只显示原图的1/8通过BitmapFactory.Options 来实现
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inSampleSize = 8;
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
imv.setImageBitmap(bmp);
②.根据当前屏幕分辨率的大小,加载图片
Display currentDisplay = getWindowManager().getDefaultDisplay();
int dw = currentDisplay.getWidth();
int dh = currentDisplay.getHeight();


BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true; //只读取图像信息,不加载图片
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);
Log.v("HEIGHTRATIO",""+heightRatio);
Log.v("WIDTHRATIO",""+widthRatio);
//判断是否要进行缩放
if (heightRatio > 1 && widthRatio > 1)
{
if (heightRatio > widthRatio)
{
//高度变化大,按高度缩放
bmpFactoryOptions.inSampleSize = heightRatio;
}else
{
// 宽度变化大,按宽度缩放
bmpFactoryOptions.inSampleSize = widthRatio;
}
}
bmpFactoryOptions.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
ceil() 方法执行的是向上取整计算,它返回的是大于或等于函数参数,并且与之最接近的整数。
2. 获取Exif图片信息
//从文件获取exif信息
ExifInterface ei = new ExifInterface(imageFilePath);
String imageDescription = ei.getAttribute("ImageDescription");
if (imageDescription != null)
{
  Log.v("EXIF", imageDescription);
}
//把exif信息写到文件:
ExifInterface ei = new ExifInterface(imageFilePath);
ei.setAttribute("ImageDescription","Something New");
3. 从gallery获取一个图片
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(“image/*”);
intent.getData();  // 获取image的uri
Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值