0
我創建了一個小應用程序,使得當我點擊按鈕時,顯示的圖像應該旋轉。我寫了下面的代碼:旋轉按鈕上的圖像點擊
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.widget.ImageView;
public class ImageActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void Rotate()
{
ImageView img = (ImageView)findViewById(R.id.imageView01);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.bharath);
// Getting width & height of the given image.
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting pre rotate to 90
Matrix mtx = new Matrix();
mtx.preRotate(90);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
img.setImageDrawable(bmd);
}
現在,當我執行的代碼,然後單擊按鈕旋轉圖像,應用程序迫使我關閉它,提有一個意外的錯誤。我無法追查和糾正。在這方面可以幫助我嗎?
請給人們的信用爲自己的努力幫助你和[接受答案(HTTP://元.stackexchange.com/a/5235/164138)。你沒有接受一個單一的答案! – THelper 2011-12-15 10:04:36