2017-07-06 40 views

回答

2

不使用庫只是我們可以用帆布和油漆概念

Point point=new Point(); 
point.set(180, 1000); 
Bitmap b=waterMark(BitmapFactory.decodeResource(getResources(), R.drawable.image),"your Text",point,Color.WHITE,90,30,true); 
imageView.setImageBitmap(b); 

方法代碼

public Bitmap waterMark(Bitmap src, String watermark, Point location, int color, int alpha, int size, boolean underline) { 
//get source image width and height 
int w = src.getWidth(); 
int h = src.getHeight(); 

Bitmap result = Bitmap.createBitmap(w, h, src.getConfig()); 
//create canvas object 
Canvas canvas = new Canvas(result); 
//draw bitmap on canvas 
canvas.drawBitmap(src, 0, 0, null); 
//create paint object 
Paint paint = new Paint(); 
//apply color 
paint.setColor(color); 
//set transparency 
paint.setAlpha(alpha); 
//set text size 
paint.setTextSize(size); 
paint.setAntiAlias(true); 
//set should be underlined or not 
paint.setUnderlineText(underline); 
//draw text on given location 
    canvas.drawText(watermark, location.x, location.y, paint); 
return result; 
} 
+0

謝謝水印圖片,我嘗試過,但它是很難進行定製。我嘗試通過waterMaker.xml - >位圖來回退,但是計算大小不同的位圖中的水印大小,並且最終在imageView中顯示,效果不是很好 – zhangle

+0

您可以自定義alpha值水印文字的透明度 – sasikumar