android圖片添加文字
① android怎樣實現在圖片上任意位置添加文字 要代碼 急求。。
android在圖片上任意位置添加文字,可以使用canvas類進行操作,實例如下:
java">@Override
protectedvoidonDraw(Canvascanvas)
{
super.onDraw(canvas);
canvas.drawBitmap(m_LogInBmp,null,m_LogIndst,m_txBackPaint);
floattleft=m_LogIndst.left+(m_LogIndst.right-m_LogIndst.left-FontWidth*m_TextLogIn.length())/2;
floatttop=m_LogIndst.top+(m_LogIndst.bottom-m_LogIndst.top-FontHeight)/2+FontHeight;
canvas.drawText(m_TextLogIn,tleft,ttop,mLogInPaint);
}
② Android圖片添加豎排文字水印
在相機設置里選擇水印。
進入相機拍照界面,選擇「水印模式」(或進入圖庫,打開某張圖片,點擊編輯-水印),然後選擇一種帶文字水印,點擊虛線文本框,即可修改內容。
③ Android給圖片添加文字和水印
話不多說 上圖
在Activity中獲取到ImageView對象,並且獲取Bitmap對象,對Bitmap進行canva繪圖,添加水印
添加一個布局,上面是原始圖片,下面是添加水印後的圖片
④ Android給圖片添加豎排文字水印
就下載一個加水印的軟體就可以了。
文字水印代碼:
privateBitmapcreateBitmap(Bitmapphoto,Stringstr,intmark_x,intmark_y){
intwidth=photo.getWidth(),hight=photo.getHeight();
System.out.println("寬"width"高"hight);
//建立一個空的BItMap
Bitmapicon=Bitmap.createBitmap(width,hight,Bitmap.Config.ARGB_8888);
//初始化畫布繪制的圖像到icon上
Canvascanvas=newCanvas(icon);
PaintphotoPaint=newPaint();//建立畫筆
photoPaint.setDither(true);//獲取跟清晰的圖像采樣
photoPaint.setFilterBitmap(true);//過濾一些
//創建一個指定的新矩形的坐標
Rectsrc=newRect(0,0,photo.getWidth(),photo.getHeight());
//創建一個指定的新矩形的坐標
Rectdst=newRect(0,0,width,hight);
//將photo縮放或則擴大到dst使用的填充區photoPaint
canvas.drawBitmap(photo,src,dst,photoPaint);