97干视频,99国产精品懂色,亚洲精品99久久久久中文字幕,伊人五月丁香综合AⅤ,国产精品成人免费999

  您的位置:華清遠(yuǎn)見教育科技集團(tuán) >> 新聞動(dòng)態(tài) >> Android資料 >> Android圖像旋轉(zhuǎn)源碼分享  
 
Android圖像旋轉(zhuǎn)源碼分享
分享到:

在Android中,圖像旋轉(zhuǎn)和圖像縮放類似,同樣是通過(guò)Matrix來(lái)實(shí)現(xiàn)的。通過(guò)Matrix的setRotate()方法可以實(shí)現(xiàn)0~360度的旋轉(zhuǎn),下面是圖像旋轉(zhuǎn)的一個(gè)例子:

代碼:圖像旋轉(zhuǎn)的實(shí)現(xiàn)

package com.miaozl.test;
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Matrix;
    import android.os.Bundle;
    import android.widget.ImageView;
    public class RotateActivity extends Activity
        {
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState)
                {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                ImageView dest = (ImageView)findViewById(R.id.dest);
                Matrix matrix = new Matrix();
                matrix.setRotate(60);
                Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.rabbit);
                Bitmap resizedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(),srcBitmap.getHeight(), matrix, true);
                    dest.setImageBitmap(resizedBitmap);
                }
        }

下面是相應(yīng)的布局文件:

< ?xml version="1.0" encoding="utf-8"?>
    < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/animlayout">
    < ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/rabbit"
        android:paddingTop="3dip"
        android:paddingBottom="3dip"/>
    < ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:id="@+id/dest"/>
    < /LinearLayout>

下圖是原圖和經(jīng)旋轉(zhuǎn)后的圖像的對(duì)比效果。

圖像旋轉(zhuǎn)的效果圖

 更多相關(guān)文章

·Android中多媒體縮略圖的生成
·Android 圖像縮放之bitmap類
·Android 2D圖像處理基本接口
·Android HTML5視頻播放
·Android基于MediaPlayer的視頻播放
·Android 中如何使用SIP服務(wù)