有时候需要在一张图片上打上一行字啊,一个日期啊什么的
下面介绍两种方法:
方法一:
Bitmap vip = BitmapFactory.decodeResource(getResources(), R.drawable.img0001); w = vip.getWidth(); h = vip.getHeight(); Canvas c = new Canvas(vip); Paint p = new Paint(); p.setTextSize(40); p.setColor(0xFF0000FF); c.drawText("abc", 50, h - 10, p);//第一个参数是想要写上面的字符串,第二, 三个是位置的XY坐标
方法二:
Bitmap vip = BitmapFactory.decodeResource(getResources(), R.drawable.img0001); Bitmap c =Bitmap.createBitmap(vip.getWidth(),vip.getHeight(),Bitmap.Config.ARGB_8888); Paint p = new Paint(); p.setColor(Color.RED); p.setTextSize(40); Canvas canvas = new Canvas(c); canvas.drawBitmap(vip, new Matrix(), null); canvas.drawText("abc", 60,40, p);
运行结果: