bitmap+文本生成新的bitmap的实现
注:参数content为生成二维码bitmap的内容,该二维码bitmap在和文本title组合生成一个新的bitmap
package info.ecloud.merchant.util; import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect; import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.journeyapps.barcodescanner.BarcodeEncoder; import java.util.Hashtable; public class SaveImageUtils { private static final String CHARSET = "UTF-8";
/**
* 生成图片 加上title的图片
* @param content
* @param title
* @return
*/
public static Bitmap createImage(String content,String title) {
int picWidth = ;//生成图片的宽度
int picHeight = ;//生成图片的高度
int titleTextSize = ;
int textColor = Color.BLACK;
int qrWidth = ;
int qrHeight = ;
int paddingTop = ;
int paddingMiddle = ;
int paddingBottom = ; //最终生成的图片
Bitmap result = Bitmap.createBitmap(picWidth,picHeight,Bitmap.Config.ARGB_8888); Paint paint = new Paint();
paint.setColor(Color.WHITE);
Canvas canvas = new Canvas(result); //先画一整块白色矩形块
canvas.drawRect(,,picWidth,picHeight,paint); //画title文字
Rect bounds = new Rect();
paint.setColor(textColor);
paint.setTextSize(titleTextSize);
//获取文字的字宽高,以便将文字与图片中心对齐
paint.getTextBounds(title,,title.length(),bounds);
//画白色矩形块
int qrTop = paddingTop+titleTextSize+paddingMiddle;//二维码的顶部高度 //画二维码
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, );
Bitmap image = null;
try {
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
image = barcodeEncoder.encodeBitmap((String) content, BarcodeFormat.QR_CODE, , );
} catch (Exception e) {
e.printStackTrace();
} paint.setColor(Color.BLACK);
canvas.drawBitmap(image,(picWidth-qrWidth)/,qrTop,paint); //画文字
paint.setColor(Color.BLACK);
paint.setTextSize(titleTextSize);
int line = ;
int textTop = qrTop+qrHeight+paddingBottom;//地址的顶部高度 for (int i = ; i < line ; i++){
String[] split = title.split("-");
paint.getTextBounds(title,,split[i].length(),bounds);
canvas.drawText(split[i],picWidth/-bounds.width()/,textTop+i*titleTextSize+i*+bounds.height()/,paint);
} canvas.save();
canvas.restore(); return result;
} }
bitmap+文本生成新的bitmap的实现的更多相关文章
- android Bitmap(将视图转为bitmap对象)
1)从android的资源文件夹layout中加载xml布局文件,并把布局文件映射为Bitmap main.xml文件如下: <?xmlversion="1.0"encodi ...
- C#图片裁切,生成新图片
/// 图片裁剪,生成新图,保存在同一目录下,名字加_new,格式1.png 新图1_new.png /// </summary> /// <param name="pic ...
- Texygen文本生成,交大计算机系14级的朱耀明
文本生成哪家强?上交大提出基准测试新平台 Texygen 2018-02-12 13:11测评 新智元报道 来源:arxiv 编译:Marvin [新智元导读]上海交通大学.伦敦大学学院朱耀明, 卢思 ...
- Android从本地选择图片文件转为Bitmap,并用zxing解析Bitmap
如何从本地选择图片文件 使用Intent调用系统相册后,onActivityResult函数返回的是Uri格式的路径 /** * 打开系统相册 */ private void openSysAlbum ...
- phpword读取内容和样式 生成新的内容
table样式还未读出 正在测试中, 目前有 rows cell textrun等样式 顺序不固定 可以设定 <?php require 'vendor/autoload.php'; use P ...
- 斯坦福NLP课程 | 第15讲 - NLP文本生成任务
作者:韩信子@ShowMeAI,路遥@ShowMeAI,奇异果@ShowMeAI 教程地址:http://www.showmeai.tech/tutorials/36 本文地址:http://www. ...
- 【转】Drawable /Bitmap、String/InputStream、Bitmap/byte[]
原文:http://wuxiaolong.me/2015/08/10/Drawable-to-Bitmap/ Drawable互转Bitmap Drawable转Bitmap 1234 Resourc ...
- IOS 截取图片 部分 并生成新图片
/** * 从图片中按指定的位置大小截取图片的一部分 * * @param image UIImage image 原始的图片 * @param rect CGRect rect 要截取的区域 * * ...
- 根据backup-my.cnf来生成新的事务日志文件
使用rpm包安装xtrabackup ## 安装依赖包yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-D ...
随机推荐
- Dart语言学习(六) Dart 列表List数组
创建List : var list = [1,2,3,"Dart",true]; 创建不可变List : var list = const [1,2,3,"Dart&qu ...
- QTP测试web时:打开ie浏览器进行录制但qtp录制脚本为空
1. 关闭ie的保护模式:设置——internet选项——安全——取消勾选“启用保护模式” 这一步很关键,之前试过很多步骤,只有这个成功了. 修改后如果可行即可.如果不行再进行下面操作: 2.关闭杀毒 ...
- django cms 5月第一弹
官方文档: ##http://django-cms.readthedocs.io/en/latest/index.html #截图 #生存的项目结构
- BZOJ 1152 歌唱王国
题目传送门 分析: 这道题很神仙,我们给出低配版解法和高配版解法2333 低配版: 首先知道这样一个公式...(证明去高配版) 当一个字符串S其中S [ 1 , i ] = S [ n - i + 1 ...
- markdown常用语法使用笔记+使用技巧(持续更新......)
参考引用内容: 简书教程 一 基本语法 1. 标题 语法: 在想要设置为标题的文字前面加#来表示,一个#是一级标题,二个#是二级标题,以此类推.支持六级标题. 注:标准语法一般在#后跟个空格再写文字 ...
- 基于 H5 和 webGL 的 3d 智慧城市
前言 中共中央.国务院在今年12月印发了<长江三角洲区域一体化发展规划纲要>(下文简称<纲要>),并发出通知,要求各地区各部门结合实际认真贯彻落实. <纲要>强调, ...
- 死磕java(1)
java入门 package com.sougn.new1; public class new1 { /** * @param args */ public static void main ...
- tmobst6
1.(单选题)Oracle数据库中,在SQL语句中连接字符串的方法是:(). A)CAT B)CONCAT C)JOIN D)UNION 2.(单选题)在数据库中,有一个名为seq的序列对象,以下语句 ...
- [python]locals内置函数
locals() Update and return a dictionary representing the current local symbol table. Free variables ...
- HDU_5045_状态压缩dp
http://acm.hdu.edu.cn/showproblem.php?pid=5045 i从1到m依次更新,dp[i][j]表示更新到i题时,j表示每个人的答题状态,分别用0和1表示(因为每个人 ...