我已经使用eclipse为android应用程序编写了一些代码。以下是我的Activity.java类。当我执行我的代码时,图像只旋转一次,如果再次单击该按钮,则图像没有被旋转,同时它向我显示6291456字节的外部分配对于这个过程来说太大了。“”错误。旋转图像多于一次
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.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class ImageActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
ImageView img;
Bitmap bmp;
Bitmap rotatedBMP;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
img = (ImageView) findViewById(R.id.imageView01);
bmp = BitmapFactory.decodeResource(getResources(),R.drawable.bharath);
int w = bmp.getWidth();
int h = bmp.getHeight();
Matrix mtx = new Matrix();
mtx.preRotate(90);
rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
img.setImageBitmap(rotatedBMP);
}
}
你正在旋转的默认图像一次又一次不是被打断的,也没有释放内存这就是为什么面对6291456字节的外部 – ingsaurabh 2011-12-27 12:00:53