[android studio添加图片]Android实现为图片添加水印

更新时间:2021-06-13    来源:SAP    手机版     字体:

【www.bbyears.com--SAP】

 代码如下

publicclassMainActivityextendsAppCompatActivity {

 

  @Override

  protectedvoidonCreate(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);

  }

 

  privateBitmap createWatermark(Bitmap bitmap, String mark) {

    intw = bitmap.getWidth();

    inth = bitmap.getHeight();

    Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas canvas =newCanvas(bmp);

    Paint p =newPaint();

    // 水印颜色

    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();

    returnbmp;

  }

 

}

效果图

本文来源:http://www.bbyears.com/qiyexinxihua/123527.html

热门标签

更多>>

本类排行