android图片加水印,文字
两种方法:
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图片加水印,文字的更多相关文章
- 图片加水印文字,logo。生成缩略图
简单JSP代码 图片加水银文字 try { String path = request.getRealPath("images\\01.jpg"); out.print(path) ...
- php 图片加水印文字水印
/*给图片加文字水印的方法*/ $dst_path = 'http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg';//保证路径正确 $dst = ...
- PHP图片加水印文字及图片合成缩放
<?php //图片添加文字水印 /*$bigImgPath = 'background.png'; $img = imagecreatefromstring(file_get_contents ...
- php对图片加水印--将文字作为水印加到图片
方法代码: /** * 图片加水印(适用于png/jpg/gif格式) * * @author flynetcn * * @param $srcImg 原图片 * @param $wat ...
- thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印
今天分享一下thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印.博主是新手,在这里卡住了很久(>_<) thinkphp 3.2.3整合ueditor 1.4 下载 ...
- Android图片加载库的理解
前言 这是“基础自测”系列的第三篇文章,以Android开发需要熟悉的20个技术点为切入点,本篇重点讲讲Android中的ImageLoader这个库的一些理解,在Android上最让人头疼是 ...
- php 分享两种给图片加水印的方法
本文章向码农们介绍 php 给图片加水印的两种方法,感兴趣的码农可以参考一下本文章的源代码. 方法一:PHP最简单的加水印方法 <?php // http://www.manongjc.com ...
- Java图片处理(二)图片加水印
图片加水印,是通过图片重叠绘制实现的.实现代码如下: public static void press(String pressImg, String pressText, String target ...
- c#封装DBHelper类 c# 图片加水印 (摘)C#生成随机数的三种方法 使用LINQ、Lambda 表达式 、委托快速比较两个集合,找出需要新增、修改、删除的对象 c# 制作正方形图片 JavaScript 事件循环及异步原理(完全指北)
c#封装DBHelper类 public enum EffentNextType { /// <summary> /// 对其他语句无任何影响 /// </summary> ...
随机推荐
- Java 中值传递和引用传递 区分
详细参见 http://blog.csdn.net/zzp_403184692/article/details/8184751
- urllib2 之info 学习
之前介绍了根据old_url获取真实url的geturl的方法,而根据urlopen返回的应答对象的info方法可以获取服务器发送头部headers的内容,并且通过字典形式反馈出来,同样测试代码如下: ...
- 利用python httplib模块 发送Post请求测试web服务是否正常起来!
最近在学习python,恰好老大最近让我搞个基于post请求测试web服务是否正常启用的小监控,上网查了下资料,发现强大的Python恰好能够用上,所以自己现学现卖,顺便锻炼下自己. 由于本人也刚接触 ...
- stl 生产全排列 next_permutation
#include<stdio.h>#include<algorithm>using namespace std;int main(){ int n,p[10]; scanf(& ...
- Git一些其它的功能
Git 开始之前我们配置过user.name和user.email.其实还有很多其他的配置项 例如:让Git显示颜色,会让命令输出来更醒目: $ git config --global color.u ...
- ural 1073.Square Country(动态规划)
1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...
- 关于oracle数据库(6)约束
约束类型 1.主键primary key(一般是一个表的标志,所以一个表只能有一个主键:主键不能为空,不能重复) 2.唯一键unique(不能重复) 3.外键foreign key 4.检查约束che ...
- Stash安装和破解
参考资料: http://www.unxmail.com/?p=590 上篇介绍了,Atlassian Stash v2.12.1 破解版的下载, 有同学不会安装. 我重新整理了下文档. 表述我的安装 ...
- windows任务计划程序路径设置
用任务计划启动程序,特别是脚本,比如我要启动python脚本,其中有一句是这么写的 BasePath = removeLastSlash(os.path.abspath("..\\..\\& ...
- DateUtils时间工具类探究
首先声明一下,这个DateUtils工具类不是自己写的,而是在commons-lang-2.Xjar包或是commons-lang3-3.X.jar包中,具体在哪个jar包中,看程序具体添加了哪个版本 ...