Android图形处理基本api(缩放,旋转,平移)

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
        //show original pic
        ImageView iv_scr=(ImageView) findViewById(R.id.iv_src);
        //copy
        ImageView iv_copy=(ImageView) findViewById(R.id.iv_copy);
        
        //1.1 manipulate pic
        Bitmap srcBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.aaa);
        iv_scr.setImageBitmap(srcBitmap);
        
        //2 establish copy of original pic
        
        //2.1 create template 
        Bitmap copyBitmap=Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(),srcBitmap.getConfig());
        //2.2create a paint
        Paint paint=new Paint();
        //2.3create canvas
        Canvas canvas=new Canvas(copyBitmap);
        //2.4 start drawing
        //2.5 manipulate copy
        
        Matrix matrix=new Matrix();
        //旋转
//        matrix.setRotate(90, srcBitmap.getWidth()/2, srcBitmap.getHeight()/2);
        //缩放
//        matrix.setScale(0.5f, 0.5f);
        //平移
//        matrix.setTranslate(30, 0);
        //镜面效果
//        matrix.setScale(-1.0f, 1);
//        matrix.postTranslate(srcBitmap.getWidth(), 0);
        //镜面效果2
        matrix.setScale(1,-1.0f);
        matrix.postTranslate(0,srcBitmap.getHeight());
        
        canvas.drawBitmap(srcBitmap, matrix, paint);
        
        
        //3 show copy
        iv_copy.setImageBitmap(copyBitmap);
    }
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     >

    <ImageView
        android:id="@+id/iv_src"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

    <ImageView
        android:id="@+id/iv_copy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</LinearLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值