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

Android 旋轉(zhuǎn)圖片

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
    import android.app.Activity;  
    import android.graphics.Bitmap;  
    import android.graphics.Matrix;  
    import android.graphics.drawable.BitmapDrawable;  
    import android.os.Bundle;  
    import android.view.View;  
    import android.view.View.OnClickListener;  
    import android.view.animation.Animation;  
    import android.view.animation.Animation.AnimationListener;  
    import android.view.animation.RotateAnimation;  
    import android.widget.Button;  
    import android.widget.ImageView;  
    import android.widget.LinearLayout;  
      
    public class RotateBitmapActivity extends Activity {  
          
        Button btnRotate1, btnRotate2;  
        ImageView ivBitmap;  
          
        //逆時(shí)針轉(zhuǎn)45度  
        RotateAnimation rotateAnimation = new RotateAnimation(0, -45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);  
          
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            // TODO Auto-generated method stub  
            super.onCreate(savedInstanceState);  
            setTitle("旋轉(zhuǎn)圖片");  
            setContentView(R.layout.rorate_bitmap);  
            btnRotate1 = (Button) findViewById(R.id.btn_rorate);  
            btnRotate2 = (Button) findViewById(R.id.btn_rorate_anim);  
            ivBitmap = (ImageView) findViewById(R.id.iv_bitmap);  
              
            btnRotate1.setOnClickListener(new OnClickListener() {  
                  
                @Override  
                public void onClick(View v) {  
                    // TODO Auto-generated method stub  
                    rotateBitmap1();  
                }  
            });  
            btnRotate2.setOnClickListener(new OnClickListener() {  
                  
                @Override  
                public void onClick(View v) {  
                    // TODO Auto-generated method stub  
                    rotateBitmap2();  
                }  
            });  
        }  
        /** 
         * 使用矩陣對(duì)象 旋轉(zhuǎn) 
         */  
        private void rotateBitmap1() {  
            LinearLayout linLayout = new LinearLayout(this);   
            BitmapDrawable bitmapDrawable = (BitmapDrawable) ivBitmap.getDrawable();  
            //獲取這個(gè)圖片的寬和高  
            int width = bitmapDrawable.getBitmap().getWidth();   
            int height = bitmapDrawable.getBitmap().getHeight();   
            //定義預(yù)轉(zhuǎn)換成的圖片的寬度和高度  
            int newWidth = getWindow().getWindowManager().getDefaultDisplay().getWidth() / 2;   
            int newHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight() / 2;  
            //計(jì)算縮放率,新尺寸除原始尺寸  
            float scaleWidth = ((float) newWidth) / width;   
            float scaleHeight = ((float) newHeight) / height;   
            // 創(chuàng)建操作圖片用的matrix對(duì)象  
            Matrix matrix = new Matrix();   
            // 縮放圖片動(dòng)作  
            matrix.postScale(scaleWidth, scaleHeight);   
            //旋轉(zhuǎn)圖片 動(dòng)作  
            matrix.postRotate(90);   
            // 創(chuàng)建新的圖片  
            Bitmap resizedBitmap = Bitmap.createBitmap(bitmapDrawable.getBitmap(), 0, 0, width, height, matrix, true);   
             
            ivBitmap.setImageBitmap(resizedBitmap);  
        }  
          
        /** 
         * 通過動(dòng)畫方式旋轉(zhuǎn),實(shí)際位置沒有改變,當(dāng)再次運(yùn)行該函數(shù),圖像還是從原來的位置開始轉(zhuǎn)動(dòng) 
         */  
        private void rotateBitmap2() {  
               
            rotateAnimation.setDuration(1000);  
            ivBitmap.startAnimation(rotateAnimation);  
              
            rotateAnimation.setAnimationListener(new AnimationListener() {  
                  
                @Override  
                public void onAnimationStart(Animation animation) {  
                    // TODO Auto-generated method stub  
                      
                }  
                  
                @Override  
                public void onAnimationRepeat(Animation animation) {  
                    // TODO Auto-generated method stub  
                      
                }  
                  
                @Override  
                public void onAnimationEnd(Animation animation) {  
                    // TODO Auto-generated method stub  
                    rotateAnimation.setFillAfter(true);//動(dòng)畫后的效果固定下來,實(shí)際圖片位置沒有改變  
                    //逆時(shí)針轉(zhuǎn)45度  坐標(biāo)點(diǎn)算不好,  
    //              ivBitmap.layout(l, t, r, b);  
                }  
            });  
              
        }  
          
          
    }  

標(biāo)簽: isp

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

上一篇:C#創(chuàng)建、讀取和修改Excel

下一篇:Android利用DrawerLayout實(shí)現(xiàn)抽屜效果