引用:http://blog.csdn.net/cq361106306/article/details/8142526

  1. 两种方法:
  2. 1.直接在图片上写文字
  3. String str = "PICC要写的文字";
  4. ImageView image = (ImageView) this.findViewById(R.id.ImageView);
  5. Bitmap photo = BitmapFactory.decodeResource(this.getResources(), R.drawable.text);
  6. int width = photo.getWidth(), hight = photo.getHeight();
  7. System.out.println("宽"+width+"高"+hight);
  8. icon = Bitmap.createBitmap(width, hight, Bitmap.Config.ARGB_8888); //建立一个空的BItMap
  9. Canvas canvas = new Canvas(icon);//初始化画布绘制的图像到icon上
  10. Paint photoPaint = new Paint(); //建立画笔
  11. photoPaint.setDither(true); //获取跟清晰的图像采样
  12. photoPaint.setFilterBitmap(true);//过滤一些
  13. Rect src = new Rect(0, 0, photo.getWidth(), photo.getHeight());//创建一个指定的新矩形的坐标
  14. Rect dst = new Rect(0, 0, width, hight);//创建一个指定的新矩形的坐标
  15. canvas.drawBitmap(photo, src, dst, photoPaint);//将photo 缩放或则扩大到 dst使用的填充区photoPaint
  16. Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);//设置画笔
  17. textPaint.setTextSize(20.0f);//字体大小
  18. textPaint.setTypeface(Typeface.DEFAULT_BOLD);//采用默认的宽度
  19. textPaint.setColor(Color.RED);//采用的颜色
  20. //textPaint.setShadowLayer(3f, 1, 1,this.getResources().getColor(android.R.color.background_dark));//影音的设置
  21. canvas.drawText(str, 20, 26, textPaint);//绘制上去字,开始未知x,y采用那只笔绘制
  22. canvas.save(Canvas.ALL_SAVE_FLAG);
  23. canvas.restore();
  24. image.setImageBitmap(icon);
  25. saveMyBitmap(icon);
  26. 2.将两个图片合成
  27. onCreat方法里面{
  28. Bitmap mark = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
  29. Bitmap photo = BitmapFactory.decodeResource(this.getResources(), R.drawable.text);
  30. Bitmap a = createBitmap(photo,mark);
  31. image.setImageBitmap(a);
  32. saveMyBitmap(a);
  33. }
  34. private Bitmap createBitmap( Bitmap src, Bitmap watermark )
  35. {
  36. String tag = "createBitmap";
  37. // Log.d( tag, "create a new bitmap" );
  38. if( src == null )
  39. {
  40. return null;
  41. }
  42. int w = src.getWidth();
  43. int h = src.getHeight();
  44. int ww = watermark.getWidth();
  45. int wh = watermark.getHeight();
  46. //create the new blank bitmap
  47. Bitmap newb = Bitmap.createBitmap( w, h, Config.ARGB_8888 );
  48. //创建一个新的和SRC长度宽度一样的位图
  49. Canvas cv = new Canvas( newb );
  50. //draw src into
  51. cv.drawBitmap( src, 0, 0, null );//在 0,0坐标开始画入src
  52. //draw watermark into
  53. cv.drawBitmap( watermark, w - ww + 5, h - wh + 5, null );//在src的右下角画入水印
  54. //save all clip
  55. cv.save( Canvas.ALL_SAVE_FLAG );//保存
  56. //store
  57. cv.restore();//存储
  58. return newb;
  59. }
  60. //保存图片到data下面
  61. public void saveMyBitmap(Bitmap bmp){
  62. FileOutputStream fos = null;
  63. try {
  64. fos = openFileOutput("image1.jpg", Context.MODE_PRIVATE);
  65. bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
  66. } catch (FileNotFoundException e) {
  67. } finally {
  68. if (fos != null) {
  69. try {
  70. fos.flush();
  71. fos.close();
  72. } catch (IOException e) {
  73. }
  74. }
  75. }
  76. }

android 文字图片合成的更多相关文章

  1. 移动端canvas文字图片合成并生成图片(canvas宽度自适应移动端屏幕)

    这是我之前做的一个关于文字图片合成的代码,供大家参考,不足支出还望体谅:具体的注释在代码里都有,有什么不懂了可以留言互相交流.<!DOCTYPE html> <html lang=& ...

  2. android开发 图片合成

    private static Bitmap compositeImages(Bitmap srcBitmap,Bitmap dstBitmap){ Bitmap bmp = null; //下面这个B ...

  3. php 图片添加文字水印 以及 图片合成(微信快码传播)

    1.图片添加文字水印: $bigImgPath = 'backgroud.png'; $img = imagecreatefromstring(file_get_contents($bigImgPat ...

  4. Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现

    Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现 暂时还未有时间开发这效果,所以先贴出来. 先贴一张效果图,这是一张手机截屏: 左上方的风景图:背景图片 右上方的人物图:前景图 ...

  5. iOS 图片水印、图片合成文字或图片实现

    这个需求可能有时候会碰到,比如自己的照片加版权,打水印等 网上的方法,有不少感觉不全对,或者需求不是特全,这里我总结了3种场景下的需求: 1.本地图片合成文字 2.本地图片合成图片 3.网络图片先下载 ...

  6. php 图片合成时文字颜色丢失

    最近在做图片合成的时候无意间发现文字颜色丢失了,仔细找了以后才发现原来是因为图片格式的原因 当图片是png图片时文字的颜色就变成了白色的,So.........去你妹的png,用jpg吧! $dest ...

  7. CxImage透明图片合成和文字叠加

    1         CxImage的作用 CxImage将几张图片合成一张图片,在一张底图上添加图片,有些图片是有透明效果的,实现图片之间的透明重叠效果.另外还可以添加文字. (1)背景图片mymix ...

  8. Android -- 图片处理, 画画板,缩放,旋转,平移,镜面,倒影,图片合成,颜色处理

    1. 画画板 示例代码 public class MainActivity extends Activity { private ImageView iv; private Bitmap baseBi ...

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

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

随机推荐

  1. PHP的学习--cookie和session--来自copy_02

    PHP的学习--cookie和session   最近读了一点<PHP核心技术与最佳实践>,看了cookie和session,有所收获,结合之前的认识参考了几篇博客,总结一下-- 1. P ...

  2. 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 ...

  3. Sqoop_ 从 hive 导到mysql常遇九问题总结(转)

    以前以为版本不同,遇到的问题就不同,后来发现,无论是新版本,还是老版本,遇到的问题大部分都是相同的.下面解决问题的方法仅供借鉴 1.拒绝连接的错误表现是什么?2.表不存在该如何解决?3.null字段填 ...

  4. 段落的展开收起(substring的应用)

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  5. 所有设备的CSS像素

    mydevice.io Mobile devices, in Responsive Web Design, relate to a core value which is the value of C ...

  6. spring security防御会话伪造session攻击

    1. 攻击场景 session fixation会话伪造攻击是一个蛮婉转的过程. 比如,当我要是使用session fixation攻击你的时候,首先访问这个网站,网站会创建一个会话,这时我可以把附有 ...

  7. docker pipework

    #!/bin/bash #auto install docker and Create VM #Define PATH Varablies IPADDR=`ifconfig |grep "B ...

  8. result结果集

    结果集(ResultSet)是数据中查询结果返回的一种对象,可以说结果集是一个存储查询结果的对象,但是结果集并不仅仅具有存储的功能,他同时还具有操纵数据的功能,可能完成对数据的更新等. 结果集读取数据 ...

  9. SpringBoot实例

    7player 7号球员 -- Show Time !跳至内容 首发 左边锋 技术流 外援 教练 7号 基于SpringBoot + Mybatis实现SpringMVC Web项目[原创] 目录 [ ...

  10. Beta阶段站立会议-01

    组名:金州勇士 组长:尹良亮 组员:王汉斌.杜月.闫浩楠 代码地址: ssh:git@git.coding.net:handsomeman/examm.githttps://git.coding.ne ...