zoukankan      html  css  js  c++  java
  • android实现图片旋转

    根据给定的源图片以及需要旋转的任意角度执行图片旋转变换。

        /*
         * 
         * @Title: bitmapRotation
         * @Description: 图片旋转
         * @param bm
         * @param orientationDegree
         * @return Bitmap
         * @throws
         */
        public Bitmap bitmapRotation(Bitmap bm, final int orientationDegree) {
    
            Matrix m = new Matrix();
            m.setRotate(orientationDegree, (float) bm.getWidth() / 2,
                    (float) bm.getHeight() / 2);
            float targetX, targetY;
            if (orientationDegree == 90) {
                targetX = bm.getHeight();
                targetY = 0;
            } else if (orientationDegree == 270) {
                targetX = 0;
                targetY = bm.getWidth();
            } else {
                targetX = bm.getHeight();
                targetY = bm.getWidth();
            }
    
            final float[] values = new float[9];
            m.getValues(values);
    
            float x1 = values[Matrix.MTRANS_X];
            float y1 = values[Matrix.MTRANS_Y];
    
            m.postTranslate(targetX - x1, targetY - y1);
    
            Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(),
                    Bitmap.Config.ARGB_8888);
    
            Paint paint = new Paint();
            Canvas canvas = new Canvas(bm1);
            canvas.drawBitmap(bm, m, paint);
    
            return bm1;
        }
  • 相关阅读:
    for 续1
    8 解决多线程对共享数据出错
    7 多线程 全局变量
    6 线程threading
    5 多进程copy文件
    4 进程间通信Queue [kjuː]
    3 进程池
    2 进程multiprocessing [mʌltɪ'prəʊsesɪŋ] time模块
    1 多任务fork Unix/Linux/Mac
    16 pep8 编码规范
  • 原文地址:https://www.cnblogs.com/bobshieh/p/5542547.html
Copyright © 2011-2022 走看看