中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android實現(xiàn)圖像旋轉(zhuǎn)

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
圖像旋轉(zhuǎn)的基本思想是通過Matrix類的setRotate方法設(shè)置旋轉(zhuǎn)的角度,然后使用Bitmap.createBitmap方法創(chuàng)建一個已經(jīng)旋轉(zhuǎn)了的圖像。除此之外,還可以使用Canvas.setMatrix方法設(shè)置,并直接使用drawBitmap繪制。
    public class MainActivity extends Activity{  
          
        public static int alpha=100;  
        private View myView;  
          
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(new MyView(this));  
        }  
      
        private class MyView extends View{  
            //十字扳手圖像  
            private Bitmap bitmap1;  
            //小球圖像  
            private Bitmap bitmap2;  
            //十字扳手當前角度  
            private int digree1 = 0;  
            //小球當前角度  
            private int digree2 = 360;  
      
            public MyView(Context context)  
            {  
                super(context);  
                setBackgroundColor(color.white);  
                InputStream is = getResources().openRawResource(R.drawable.cross);  
                bitmap1 = BitmapFactory.decodeStream(is);  
                is = getResources().openRawResource(R.drawable.ball);  
                bitmap2 = BitmapFactory.decodeStream(is);  
            }  
      
            @Override  
            protected void onDraw(Canvas canvas)  
            {  
                Matrix matrix = new Matrix();  
                //講旋轉(zhuǎn)角度控制在0-360  
                if (digree1 > 360)  
                    digree1 = 0;  
                if(digree2 < 0)  
                    digree2 = 360;  
                //設(shè)置旋轉(zhuǎn)角度和旋轉(zhuǎn)中心點  
                matrix.setRotate(digree1++, 160, 240);                        
                canvas.setMatrix(matrix);  
                //繪制圖像  
                canvas.drawBitmap(bitmap1, 88, 169, null);  
                //設(shè)置旋轉(zhuǎn)角度和旋轉(zhuǎn)中心點  
                matrix.setRotate(digree2--,160 , 240);  
                canvas.setMatrix(matrix);    
                //繪制圖像  
                canvas.drawBitmap(bitmap2, 35, 115, null);  
                //在onDrow中調(diào)用invalidate方法,表示不斷重繪,即實現(xiàn)動畫效果  
                invalidate();  
            }  
        }  
    }  

標簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:一個php 生成zip文件的類

下一篇:面向?qū)ο蟮膍ysql數(shù)據(jù)庫操作php類