标签:
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() 获取image的uri Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().
版权声明:本文为博主原创文章,未经博主允许不得转载。 19_Android中图片处理原理篇,关于人脸识别网站,图片加载到内存,图片缩放,图片翻转倒置,网上撕衣服游戏案例编写 标签: 原文地址:http://blog.csdn.net/tototuzuoquan/article/details/46948469 |