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