@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imageView = (ImageView)findViewById(R.id.myimg);
Bitmap bmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.background);
Bitmap newb = Bitmap.createBitmap(320,480,Config.ARGB_8888);
Canvas canvasTmp = new Canvas(newb);
canvasTmp.drawColor(Color.TRANSPARENT);
Paint p = new Paint();
Typeface font = Typeface.create("宋体", Typeface.BOLD);
p.setColor(Color.RED);
p.setTypeface(font);
p.setTextSize(16);
canvasTmp.drawBitmap(bmp, 0,0,p);
canvasTmp.drawText("文字", 0, 0, p);
canvasTmp.save(Canvas.ALL_SAVE_FLAG);
imageView.setImageBitmap(newb);
canvasTmp.restore();
}
在一张图片上写字,网上找的代码是这样的.但是坐标都为(0,0)时.图片把文字挡住了,就是看不到文字了
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imageView = (ImageView)findViewById(R.id.myimg);
Bitmap bmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.background);
Bitmap newb = Bitmap.createBitmap(320,480,Config.ARGB_8888);
Canvas canvasTmp = new Canvas(newb);
canvasTmp.drawColor(Color.TRANSPARENT);
Paint p = new Paint();
Typeface font = Typeface.create("宋体", Typeface.BOLD);
p.setColor(Color.RED);
p.setTypeface(font);
p.setTextSize(16);
canvasTmp.drawBitmap(bmp, 0,0,p);
canvasTmp.drawText("文字", 0, 0, p);
canvasTmp.save(Canvas.ALL_SAVE_FLAG);
imageView.setImageBitmap(newb);
canvasTmp.restore();
}
在一张图片上写字,网上找的代码是这样的.但是坐标都为(0,0)时.图片把文字挡住了,就是看不到文字了
http://sd4886656.iteye.com/blog/1200890