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