打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
android图像处理系列之二--图片旋转、缩放、反转

转自:http://blog.csdn.net/maylian7700/article/details/7071837

 

注意是反转,不是翻转。贴图:

原图:



处理后:



下面看代码:

  1. package com.jacp.image.util;  
  2.   
  3. import android.graphics.Bitmap;  
  4. import android.graphics.Matrix;  
  5.   
  6. /** 
  7.  * 图片处理 
  8.  *  
  9.  * @author maylian7700@126.com 
  10.  *  
  11.  */  
  12. public class ImageHandler {  
  13.   
  14.     /** 
  15.      * 图片旋转 
  16.      *  
  17.      * @param bmp 
  18.      *            要旋转的图片 
  19.      * @param degree 
  20.      *            图片旋转的角度,负值为逆时针旋转,正值为顺时针旋转 
  21.      * @return 
  22.      */  
  23.     public static Bitmap rotateBitmap(Bitmap bmp, float degree) {  
  24.         Matrix matrix = new Matrix();  
  25.         matrix.postRotate(degree);  
  26.         return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);  
  27.     }  
  28.   
  29.     /** 
  30.      * 图片缩放 
  31.      *  
  32.      * @param bm 
  33.      * @param scale 
  34.      *            值小于则为缩小,否则为放大 
  35.      * @return 
  36.      */  
  37.     public static Bitmap resizeBitmap(Bitmap bm, float scale) {  
  38.         Matrix matrix = new Matrix();  
  39.         matrix.postScale(scale, scale);  
  40.         return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);  
  41.     }  
  42.   
  43.     /** 
  44.      * 图片缩放 
  45.      *  
  46.      * @param bm 
  47.      * @param w 
  48.      *            缩小或放大成的宽 
  49.      * @param h 
  50.      *            缩小或放大成的高 
  51.      * @return 
  52.      */  
  53.     public static Bitmap resizeBitmap(Bitmap bm, int w, int h) {  
  54.         Bitmap BitmapOrg = bm;  
  55.   
  56.         int width = BitmapOrg.getWidth();  
  57.         int height = BitmapOrg.getHeight();  
  58.   
  59.         float scaleWidth = ((float) w) / width;  
  60.         float scaleHeight = ((float) h) / height;  
  61.   
  62.         Matrix matrix = new Matrix();  
  63.         matrix.postScale(scaleWidth, scaleHeight);  
  64.         return Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true);  
  65.     }  
  66.   
  67.     /** 
  68.      * 图片反转 
  69.      *  
  70.      * @param bm 
  71.      * @param flag 
  72.      *            0为水平反转,1为垂直反转 
  73.      * @return 
  74.      */  
  75.     public static Bitmap reverseBitmap(Bitmap bmp, int flag) {  
  76.         float[] floats = null;  
  77.         switch (flag) {  
  78.         case 0: // 水平反转  
  79.             floats = new float[] { -1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f };  
  80.             break;  
  81.         case 1: // 垂直反转  
  82.             floats = new float[] { 1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 1f };  
  83.             break;  
  84.         }  
  85.   
  86.         if (floats != null) {  
  87.             Matrix matrix = new Matrix();  
  88.             matrix.setValues(floats);  
  89.             return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);  
  90.         }  
  91.   
  92.         return null;  
  93.     }  
  94.   
  95. }  


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
[Android] 随时拍图像处理部分总结及源码分享
Android下常用的图像处理程序(灰度化、线性灰度变化、二值化)
拼图软件,一个就够了-Poto #iOS #Android
体验PhotoShop?CS5的超强抠图和图像处理功能 - CS5 系列
《图像处理》
图像与图像处理----从认识到认知
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服