通过设置Bitmap旋转ImageView(动态旋转图片)
来源:互联网 发布:centos中如何退出终端 编辑:程序博客网 时间:2024/05/21 17:29
java:
package EX04_25.txt;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Matrix;import android.graphics.drawable.BitmapDrawable;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.ImageView;import android.widget.ImageView.ScaleType;import android.widget.LinearLayout;public class EX04_25 extends Activity {private Button LButton;private Button RButton;private ImageView mImageView;private int degrean = 0; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initApp(); }private void initApp() {LButton = (Button)findViewById(R.id.leftButton);RButton = (Button)findViewById(R.id.rightButton);mImageView = (ImageView)findViewById(R.id.myImage);final Bitmap bmp= BitmapFactory.decodeResource(getResources(), R.drawable.woman);final int mWidth = bmp.getWidth();final int mHeight = bmp.getHeight();mImageView.setScaleType(ScaleType.CENTER); //这项设置为正常旋转Bitmap的关键// TODO Auto-generated method stubLButton.setOnClickListener(new Button.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubturnLeft();}private void turnLeft() {// TODO Auto-generated method stubdegrean--;if (degrean < -5) {degrean = -5;}Matrix mt = new Matrix();mt.postRotate(5*degrean);Bitmap turnBmp = Bitmap.createBitmap(bmp, 0, 0, mWidth, mHeight, mt, true);mImageView.setImageBitmap(turnBmp);}});RButton.setOnClickListener(new Button.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubturnRight();}private void turnRight() {// TODO Auto-generated method stubdegrean++;if (degrean > 5) {degrean = 5;}Matrix mt = new Matrix();mt.postScale(1, 1);mt.setRotate(5*degrean);Bitmap turnBmp = Bitmap.createBitmap(bmp, 0, 0, mWidth, mHeight, mt, true);BitmapDrawable turnDrawable = new BitmapDrawable(turnBmp);mImageView.setImageDrawable(turnDrawable);}});}}
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" ><Buttonandroid:id = "@+id/leftButton"android:layout_marginTop = "40dip" android:layout_marginLeft = "20dip" android:layout_width="81dip" android:layout_height="wrap_content" android:text="向左旋转" /><ImageViewandroid:id = "@+id/myImage"android:layout_marginTop = "10dip" android:layout_marginLeft = "10dip" android:layout_width="100dip" android:layout_height="125dip" android:src = "@drawable/woman" /> <Buttonandroid:id = "@+id/rightButton"android:layout_marginTop = "40dip" android:layout_marginLeft = "10dip" android:layout_width="80dip" android:layout_height="wrap_content" android:text="向右旋转" /> </LinearLayout>
- 通过设置Bitmap旋转ImageView(动态旋转图片)
- 动态旋转图片(Bitmap与Matrix 旋转ImageView)
- Bitmap与Matrix旋转ImageView
- Bitmap与Matrix旋转ImageView
- imageView图片自动360旋转
- android 图片Bitmap的旋转
- 旋转ImageView
- 旋转ImageView
- ProgressBar设置旋转图片
- Bitmap 旋转
- 通过SeekBar对ImageView进行缩放,旋转
- Swift 旋转动画 (设置的ImageView的旋转动画)
- ImageView实现图片旋转和缩放
- imageView实现图片缩放和旋转
- 自定义ImageView来实现图片旋转
- 图片处理--旋转、将View转成Bitmap
- android bitmap(图片)旋转90度
- 安卓图片Bitmap一些旋转处理
- vc模拟鼠标键盘操作实用类
- 猜猜我在想什么(以及动画xml的设置)
- 堆排序Java实现
- 我的第一个游戏FoodieThebug完成之后的心得体会--子龙山人
- 使用笔记本扩展并口+sjf2410烧写bootloader .
- 通过设置Bitmap旋转ImageView(动态旋转图片)
- 第一次移植uboot(1) .
- 古天乐养生经验——如何保持身体健康?
- Android-Lint:查错与代码优化利器
- 第一次移植uboot(2)(NAND中环境变量读写) .
- 动态缩放图片(java文件中布局控件(出现ImageView左上角位置改变的问题))
- 第一次移植uboot(3)(添加DM9000网卡支持) .
- 【thinkphp3.x】thinkphp3.x中给控制器中的操作方法指定后缀
- ANDROID 2D