我正在尝试从资源创建位图并在其上绘制一个简单的文本。代码编译并运行,但是当我单击按钮时,应用程序在 AVD 中崩溃,可能是什么问题
package apc.examples;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_me);
}
public void showAboutMessage(View v)
{
Bitmap marked= BitmapFactory.decodeResource(getResources(), R.drawable.my_image);
ImageView portrait = (ImageView) findViewById(R.id.imageView1);
Canvas canvas = new Canvas(marked);
canvas.drawBitmap(marked, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(10);
canvas.drawText("asfasf",0, 0, paint);
portrait.setImageBitmap(marked);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.about_me, menu);
return true;
}
}