package com.example.postrotate;

import android.os.*;
import android.app.*;
import android.graphics.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;

 

public class MainActivity extends Activity {

ImageView iv;
Bitmap bmp;
Matrix m;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setGravity(Gravity.CENTER);
setContentView(ll);

iv = new ImageView(this);
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.images);
iv.setImageBitmap(bmp);

ll.addView(iv);

m = new Matrix();

iv.setOnClickListener(new clickListener());
}

class clickListener implements OnClickListener{
public void onClick(View v){
m.postRotate(90);
Bitmap tmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
iv.setImageBitmap(tmp);
}
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

arrow
arrow
    創作者介紹
    創作者 痞客興 的頭像
    痞客興

    痞客興的部落格

    痞客興 發表在 痞客邦 留言(0) 人氣()