如何通过触摸事件从android中的固定点旋转图像

时间:2011-09-06 04:41:28

标签: android where-clause

package com.arun;

import android.app.Activity;
import android.os.Bundle;

import java.security.PublicKey;

import android.app.Activity;
import android.content.Intent;
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.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;

public class Rotation extends Activity implements Button.OnClickListener
{
private ImageView img;
private Button btn1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

btn1=(Button)findViewById(R.id.button2);
btn1.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    img=(ImageView)findViewById(R.id.ImageView01);
    Bitmap RBMP1 = BitmapFactory.decodeResource(getResources(), R.drawable.needle);
    int w1 = RBMP1.getWidth();
    int h1 = RBMP1.getHeight();
    // Setting post rotate to 90
    Matrix mtx1 = new Matrix();
    mtx1.postRotate(45);
    // Rotating Bitmap
    Bitmap BMP1 = Bitmap.createBitmap(RBMP1, 0, 0, w1, h1, mtx1, true);
    BitmapDrawable bmd1 = new BitmapDrawable(BMP1);
    img.setImageDrawable(bmd1);
}
}

0 个答案:

没有答案