android 图片旋转 水平翻转


1.水平翻转

  Bitmap  bitmap1=null;
        bitmap1=BitmapFactory.decodeResource(getResources(),R.drawable.icon);
        Bitmap  bitmap2 =Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);  
        Canvas canvas = new Canvas(bitmap2);
        
        Matrix orig = canvas.getMatrix(); 
        orig.setScale(-1, 1);                     //翻转X
        orig.postTranslate(bitmap1.getWidth(), 0);//平移 
        canvas.drawBitmap(bitmap1, orig, null); 
        
        ImageView ivSecond = new ImageView(this);
        ivSecond.setImageBitmap(bitmap2); 

2.旋转

Resources res = this.getContext().getResources();
 img = BitmapFactory.decodeResource(res, R.drawable.aa);
 Matrix matrix = new Matrix();
 matrix.postRotate(180); /*翻转180度*/
 int width = img.getWidth();
 int height = img.getHeight();
 img_a = Bitmap.createBitmap(img, 0, 0, width, height, matrix, true);

ivSecond.setImageBitmap(img_a );

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM