Android Image Rotate Example
来源:互联网 发布:轴承型号查询软件 编辑:程序博客网 时间:2024/05/17 13:41
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"
03
android:layout_width
=
"fill_parent"
04
android:layout_height
=
"fill_parent"
05
xmlns:android
=
"http://schemas.android.com/apk/res/android"
06
android:background
=
"#ffffff"
07
android:gravity
=
"center"
>
08
<
ImageView
android:id
=
"@+id/ImageView01"
09
android:layout_width
=
"wrap_content"
10
android:layout_height
=
"wrap_content"
11
android:src
=
"@drawable/refresh"
/>
12
</
LinearLayout
>
01
public
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,
0
,
0
, 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)
- Android Image Rotate Example
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- spring工作机制及为什么要用?
- Android HorizontalScrollview Example
- HI, HELLO
- 6.7 执行预编译/普通批处理操作标签使用
- Linux 环境变量
- Android Image Rotate Example
- 时间的表达方式
- #100319#windows下建立打不开删不掉的文件夹
- 3.4.3 选择主键
- 6.4 bboss-taglib标签库新增标签及属性说明
- Android Hide the title bar in 2 ways
- 关于泛型容器的一些使用
- 帮你学习“注册表”!
- 出来报到