android 文字图片合成
引用:http://blog.csdn.net/cq361106306/article/details/8142526
- 两种方法:
- 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 文字图片合成的更多相关文章
- 移动端canvas文字图片合成并生成图片(canvas宽度自适应移动端屏幕)
这是我之前做的一个关于文字图片合成的代码,供大家参考,不足支出还望体谅:具体的注释在代码里都有,有什么不懂了可以留言互相交流.<!DOCTYPE html> <html lang=& ...
- android开发 图片合成
private static Bitmap compositeImages(Bitmap srcBitmap,Bitmap dstBitmap){ Bitmap bmp = null; //下面这个B ...
- php 图片添加文字水印 以及 图片合成(微信快码传播)
1.图片添加文字水印: $bigImgPath = 'backgroud.png'; $img = imagecreatefromstring(file_get_contents($bigImgPat ...
- Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现
Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现 暂时还未有时间开发这效果,所以先贴出来. 先贴一张效果图,这是一张手机截屏: 左上方的风景图:背景图片 右上方的人物图:前景图 ...
- iOS 图片水印、图片合成文字或图片实现
这个需求可能有时候会碰到,比如自己的照片加版权,打水印等 网上的方法,有不少感觉不全对,或者需求不是特全,这里我总结了3种场景下的需求: 1.本地图片合成文字 2.本地图片合成图片 3.网络图片先下载 ...
- php 图片合成时文字颜色丢失
最近在做图片合成的时候无意间发现文字颜色丢失了,仔细找了以后才发现原来是因为图片格式的原因 当图片是png图片时文字的颜色就变成了白色的,So.........去你妹的png,用jpg吧! $dest ...
- CxImage透明图片合成和文字叠加
1 CxImage的作用 CxImage将几张图片合成一张图片,在一张底图上添加图片,有些图片是有透明效果的,实现图片之间的透明重叠效果.另外还可以添加文字. (1)背景图片mymix ...
- Android -- 图片处理, 画画板,缩放,旋转,平移,镜面,倒影,图片合成,颜色处理
1. 画画板 示例代码 public class MainActivity extends Activity { private ImageView iv; private Bitmap baseBi ...
- PHP图片加水印文字及图片合成缩放
<?php //图片添加文字水印 /*$bigImgPath = 'background.png'; $img = imagecreatefromstring(file_get_contents ...
随机推荐
- PHP的学习--cookie和session--来自copy_02
PHP的学习--cookie和session 最近读了一点<PHP核心技术与最佳实践>,看了cookie和session,有所收获,结合之前的认识参考了几篇博客,总结一下-- 1. P ...
- 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- Sqoop_ 从 hive 导到mysql常遇九问题总结(转)
以前以为版本不同,遇到的问题就不同,后来发现,无论是新版本,还是老版本,遇到的问题大部分都是相同的.下面解决问题的方法仅供借鉴 1.拒绝连接的错误表现是什么?2.表不存在该如何解决?3.null字段填 ...
- 段落的展开收起(substring的应用)
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- 所有设备的CSS像素
mydevice.io Mobile devices, in Responsive Web Design, relate to a core value which is the value of C ...
- spring security防御会话伪造session攻击
1. 攻击场景 session fixation会话伪造攻击是一个蛮婉转的过程. 比如,当我要是使用session fixation攻击你的时候,首先访问这个网站,网站会创建一个会话,这时我可以把附有 ...
- docker pipework
#!/bin/bash #auto install docker and Create VM #Define PATH Varablies IPADDR=`ifconfig |grep "B ...
- result结果集
结果集(ResultSet)是数据中查询结果返回的一种对象,可以说结果集是一个存储查询结果的对象,但是结果集并不仅仅具有存储的功能,他同时还具有操纵数据的功能,可能完成对数据的更新等. 结果集读取数据 ...
- SpringBoot实例
7player 7号球员 -- Show Time !跳至内容 首发 左边锋 技术流 外援 教练 7号 基于SpringBoot + Mybatis实现SpringMVC Web项目[原创] 目录 [ ...
- Beta阶段站立会议-01
组名:金州勇士 组长:尹良亮 组员:王汉斌.杜月.闫浩楠 代码地址: ssh:git@git.coding.net:handsomeman/examm.githttps://git.coding.ne ...