添加水印的方法挺简单的,具体内容如下
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView iv = (ImageView) findViewById(R.id.imageView); Drawable drawable = ContextCompat.getDrawable(this, R.drawable.image); BitmapDrawable bd = (BitmapDrawable) drawable; Bitmap bmp = bd.getBitmap(); Bitmap bitmap = createWatermark(bmp, "叶应是叶" + "http://blog.csdn.net/new_one_object"); iv.setImageBitmap(bitmap); } private Bitmap createWatermark(Bitmap bitmap, String mark) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint p = new Paint(); // 水印颜色 p.setColor(Color.parseColor("#c5576370")); // 水印字体大小 p.setTextSize(150); //抗锯齿 p.setAntiAlias(true); //绘制图像 canvas.drawBitmap(bitmap, 0, 0, p); //绘制文字 canvas.drawText(mark, 0, h / 2, p); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); return bmp; }}
效果图
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。
新闻热点
疑难解答