赞
踩
private ImageView iv_photo;
// 获取图片
Bitmap bitmap = ((BitmapDrawable)iv_photo.getDrawable()).getBitmap();
//画水印
List<String> labels = new ArrayList<>();
labels.add("公主岭市民政局");
bitmap = createWatermark(bitmap, labels);
// 设置图片
iv_photo.setImageBitmap(bitmap);
private Bitmap createWatermark(Bitmap bitmap, List<String> labels) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint p = new Paint(); // 水印颜色 p.setColor(Color.parseColor("#c5576370")); // 水印字体大小 p.setTextSize(13); //抗锯齿 p.setAntiAlias(true); //绘制图像 canvas.drawBitmap(bitmap, 0, 0, p); //绘制文字 canvas.save(); canvas.rotate(-30); float textWidth = p.measureText(labels.get(0)); int index = 0; for (int positionY = height / 10; positionY <= height; positionY += height / 10+80) { float fromX = -width + (index++ % 2) * textWidth; for (float positionX = fromX; positionX < width; positionX += textWidth * 2) { int spacing = 0;//间距 for(String label:labels){ canvas.drawText(label, positionX, positionY+spacing, p); spacing = spacing+50; } } } canvas.restore(); return bmp; }
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。