Android Image Rotate Example

In android, we can rotate the image using matrix post rotate.
Example for Android Image Rotate :-

01<?xml version="1.0" encoding="utf-8"?>
02<LinearLayout android:id="@+id/LinearLayout01"
03android:layout_width="fill_parent"
04android:layout_height="fill_parent"
06android:background="#ffffff"
07android:gravity="center">
08<ImageView android:id="@+id/ImageView01"
09android:layout_width="wrap_content"
10android:layout_height="wrap_content"
11android:src="@drawable/refresh" />
12</LinearLayout>
01public class ExampleApp extends Activity
02{
03    private ImageView img;
04 
05    @Override
06    protected void onCreate(Bundle savedInstanceState) {
07        super.onCreate(savedInstanceState);
08        setContentView(R.layout.main);
09 
10        img=(ImageView)findViewById(R.id.ImageView01);
11        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.refresh);
12               // Getting width & height of the given image.
13        int w = bmp.getWidth();
14        int h = bmp.getHeight();
15               // Setting post rotate to 90
16        Matrix mtx = new Matrix();
17        mtx.postRotate(90);
18                // Rotating Bitmap
19        Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 00, w, h, mtx, true);
20        BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
21 
22        img.setImageDrawable(bmd);
23 
24    }
25 
26}

The output will looks like (1st image is Before rotating the image, 2nd image is After rotating the image)
imagerotatebeforeimagerotateafter

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值