首页 > 移动平台 > 详细

19_Android中图片处理原理篇,关于人脸识别网站,图片加载到内存,图片缩放,图片翻转倒置,网上撕衣服游戏案例编写

时间:2015-07-19 01:27:22      阅读:271      评论:0      收藏:0      [点我收藏+]
??

1 加载图片到内存

1.数码相机照片特别是大于3m以上的,内存吃不消,会报OutOfMemoryError,若是想只显示原图片的1/8,可以通过BitmapFactory.Options来实现,具体代码如下:

BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();

bmpFactoryOptions.inSampleSize = 8;

Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);

imv.setImageBitmap(bmp);

如果图片太大,会出现的以下的问题:

技术分享

2 根据当前屏幕分辨率的大小,加载图片

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);

3 获取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");

4 gallery获取一个图片

Intent intent = new Intent(Intent.ACTION_PICK);

intent.setType(“image/*”);

intent.getData() 获取imageuri

Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().

版权声明:本文为博主原创文章,未经博主允许不得转载。

19_Android中图片处理原理篇,关于人脸识别网站,图片加载到内存,图片缩放,图片翻转倒置,网上撕衣服游戏案例编写

原文:http://blog.csdn.net/tototuzuoquan/article/details/46948469

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!