两种方法:

1.直接在图片上写文字

        String str = "PICC要写的文字";

       ImageView image = (ImageView) this.findViewById(R.id.ImageView);
Bitmap photo = BitmapFactory.decodeResource(this.getResources(), R.drawable.text);
int width = photo.getWidth(), hight = photo.getHeight();
System.out.println("宽"+width+"高"+hight);
icon = Bitmap.createBitmap(width, hight, Bitmap.Config.ARGB_8888); //建立一个空的BItMap
Canvas canvas = new Canvas(icon);//初始化画布绘制的图像到icon上 Paint photoPaint = new Paint(); //建立画笔
photoPaint.setDither(true); //获取跟清晰的图像采样
photoPaint.setFilterBitmap(true);//过滤一些 Rect src = new Rect(0, 0, photo.getWidth(), photo.getHeight());//创建一个指定的新矩形的坐标
Rect dst = new Rect(0, 0, width, hight);//创建一个指定的新矩形的坐标
canvas.drawBitmap(photo, src, dst, photoPaint);//将photo 缩放或则扩大到 dst使用的填充区photoPaint Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);//设置画笔
textPaint.setTextSize(20.0f);//字体大小
textPaint.setTypeface(Typeface.DEFAULT_BOLD);//采用默认的宽度
textPaint.setColor(Color.RED);//采用的颜色
//textPaint.setShadowLayer(3f, 1, 1,this.getResources().getColor(android.R.color.background_dark));//影音的设置
canvas.drawText(str, 20, 26, textPaint);//绘制上去字,开始未知x,y采用那只笔绘制
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
image.setImageBitmap(icon);
saveMyBitmap(icon); 2.将两个图片合成 onCreat方法里面{ Bitmap mark = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
Bitmap photo = BitmapFactory.decodeResource(this.getResources(), R.drawable.text); Bitmap a = createBitmap(photo,mark);
image.setImageBitmap(a);
saveMyBitmap(a); } private Bitmap createBitmap( Bitmap src, Bitmap watermark ) { String tag = "createBitmap"; // Log.d( tag, "create a new bitmap" ); if( src == null ) { return null; } int w = src.getWidth(); int h = src.getHeight(); int ww = watermark.getWidth(); int wh = watermark.getHeight(); //create the new blank bitmap Bitmap newb = Bitmap.createBitmap( w, h, Config.ARGB_8888 );
//创建一个新的和SRC长度宽度一样的位图 Canvas cv = new Canvas( newb ); //draw src into cv.drawBitmap( src, 0, 0, null );//在 0,0坐标开始画入src //draw watermark into cv.drawBitmap( watermark, w - ww + 5, h - wh + 5, null );//在src的右下角画入水印 //save all clip cv.save( Canvas.ALL_SAVE_FLAG );//保存 //store cv.restore();//存储 return newb; } //保存图片到data下面 public void saveMyBitmap(Bitmap bmp){
FileOutputStream fos = null;
try {
fos = openFileOutput("image1.jpg", Context.MODE_PRIVATE);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} catch (FileNotFoundException e) {
} finally {
if (fos != null) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
}
}
} }

android图片加水印,文字的更多相关文章

  1. 图片加水印文字,logo。生成缩略图

    简单JSP代码 图片加水银文字 try { String path = request.getRealPath("images\\01.jpg"); out.print(path) ...

  2. php 图片加水印文字水印

    /*给图片加文字水印的方法*/ $dst_path = 'http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg';//保证路径正确 $dst = ...

  3. PHP图片加水印文字及图片合成缩放

    <?php //图片添加文字水印 /*$bigImgPath = 'background.png'; $img = imagecreatefromstring(file_get_contents ...

  4. php对图片加水印--将文字作为水印加到图片

    方法代码: /**  * 图片加水印(适用于png/jpg/gif格式)  *  * @author flynetcn  *  * @param $srcImg  原图片  * @param $wat ...

  5. thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印

    今天分享一下thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印.博主是新手,在这里卡住了很久(>_<) thinkphp 3.2.3整合ueditor 1.4 下载 ...

  6. Android图片加载库的理解

    前言     这是“基础自测”系列的第三篇文章,以Android开发需要熟悉的20个技术点为切入点,本篇重点讲讲Android中的ImageLoader这个库的一些理解,在Android上最让人头疼是 ...

  7. php 分享两种给图片加水印的方法

    本文章向码农们介绍 php 给图片加水印的两种方法,感兴趣的码农可以参考一下本文章的源代码. 方法一:PHP最简单的加水印方法 <?php // http://www.manongjc.com ...

  8. Java图片处理(二)图片加水印

    图片加水印,是通过图片重叠绘制实现的.实现代码如下: public static void press(String pressImg, String pressText, String target ...

  9. c#封装DBHelper类 c# 图片加水印 (摘)C#生成随机数的三种方法 使用LINQ、Lambda 表达式 、委托快速比较两个集合,找出需要新增、修改、删除的对象 c# 制作正方形图片 JavaScript 事件循环及异步原理(完全指北)

    c#封装DBHelper类   public enum EffentNextType { /// <summary> /// 对其他语句无任何影响 /// </summary> ...

随机推荐

  1. OpenGL多视口

    #include <gl/glew.h> #include <gl/freeglut.h> #include <iostream> ; ; float rtri = ...

  2. HDU 2955 Robberies(01背包)

    Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...

  3. Java 算法

    1.简单的冒泡排序 //冒泡算法一共两种 // -----冒泡算法(1) int a[]={23,69,4,58,1,20}; for (int i = 0; i < a.length-1; i ...

  4. C# 几个特殊运算符的理解和Nullable<T> 的研究

    可空值类型和?运算符 谈到运算符,大家一定很熟悉,但是对所有的运算符都能掌握吗? 看了下面代码再回答. Nullable<Int32> count = ; ; bool? flag = f ...

  5. 第三次冲刺spring会议(第一次会议)

    [例会时间]2014/5/20 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳

  6. iOS 面试大全从简单到复杂(简单篇)

    1.UIWindow和UIView和 CALayer 的联系和区别? 答:UIView是视图的基类,UIViewController是视图控制器的基类,UIResponder是表示一个可以在屏幕上响应 ...

  7. html5 画个圈

    <html><body><canvas id="myCanvas" width="200" height="100&qu ...

  8. zendstudio 安装 手册

    安装 http://jingyan.baidu.com/article/b907e627b14fbb46e6891c65.html 选择baidu官方32bit安装 补丁破解网址 http://dwt ...

  9. 笔记整理--Linux_Socket

    揭开Socket编程的面纱 - 博客 - 伯乐在线 - Google Chrome (2013/9/22 19:28:24) 揭开Socket编程的面纱 2013/09/21 | 分类: IT技术 | ...

  10. IIS:错误: 无法提交配置更改,因为文件已在磁盘上更改

    文件名: \\?\C:\Windows\system32\inetsrv\config\applicationHost.config 错误: 无法提交配置更改,因为文件已在磁盘上更改 通过 Micro ...