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;
        }
  • 相关阅读:
    Mysql锁机制介绍
    开启Mysql慢查询来优化mysql
    开启mysql慢查询日志并使用mysqldumpslow命令查看
    MySQL MyISAM/InnoDB高并发优化经验
    UIPageControl
    UIPikerView的属性
    UIScrollView
    UISement属性
    UISlide属性
    UISwitch
  • 原文地址:https://www.cnblogs.com/bobshieh/p/5542547.html
Copyright © 2011-2022 走看看