当前位置: 首页 > news >正文

做网站可以用哪些语言网站建设官网制作平台

做网站可以用哪些语言,网站建设官网制作平台,关于企业网站开发与设计论文,今天石家庄出什么事了背景 说明#xff1a;本文章是介绍#xff0c;在一张背景图片中嵌入生成的二维码和中文文字。 用处#xff1a;比如活动分享二维码的时候#xff0c;提供一张背景图#xff0c;然后在背景图中嵌入二维码等。 注意#xff1a;二维码和文字的位置需要你自行调整。 一、依赖… 背景 说明本文章是介绍在一张背景图片中嵌入生成的二维码和中文文字。 用处比如活动分享二维码的时候提供一张背景图然后在背景图中嵌入二维码等。 注意二维码和文字的位置需要你自行调整。 一、依赖引入 !-- https://mvnrepository.com/artifact/com.google.zxing/zxing-parent --dependencygroupIdcom.google.zxing/groupIdartifactIdzxing-parent/artifactIdversion3.5.0/versiontypepom/type/dependency 二、创建工具类 生成工具类ImageFileUtils 1、导入包 import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.hvit.user.yst.request.CreateQrcodeRequest; import org.apache.commons.lang3.StringUtils;import javax.imageio.ImageIO; import javax.servlet.http.HttpServletResponse; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.UUID; 2、生成二维码 // 生成二维码图片// text二维码内容// size: 二维码尺寸private static BufferedImage generateQRCode(String text, int size) {MapEncodeHintType, Object hints new HashMap();hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.CHARACTER_SET, UTF-8);try {QRCodeWriter writer new QRCodeWriter();BitMatrix bitMatrix writer.encode(text, BarcodeFormat.QR_CODE, size, size, hints);int width bitMatrix.getWidth();int height bitMatrix.getHeight();BufferedImage qrImage new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);Graphics2D graphics qrImage.createGraphics();graphics.setColor(Color.WHITE);graphics.fillRect(0, 0, size, size);graphics.setColor(Color.BLACK);for (int x 0; x size; x) {for (int y 0; y size; y) {if (bitMatrix.get(x, y)) {graphics.fillRect(x, y, 1, 1);}}}// 渲染二维码Graphics2D graphics1 qrImage.createGraphics();// 添加蓝色边框int borderSize 10; // 边框大小Color myColor new Color(0x19, 0x76, 0xFF); // 红色graphics1.setColor(myColor);graphics1.fillRect(0, 0, size, borderSize); // 上边框graphics1.fillRect(0, 0, borderSize, size); // 左边框graphics1.fillRect(size - borderSize, 0, borderSize, size); // 右边框graphics1.fillRect(0, size - borderSize, size, borderSize); // 下边框return qrImage;} catch (WriterException e) {e.printStackTrace();return null;}} 说明以上生成的二维码是带有蓝色边框的二维码如图 3、在背景图片上加入文字并且居中支持\n换行 // 在图片上添加图片private static void addImageToImage(BufferedImage baseImage, BufferedImage overlayImage, int x, int y) {Graphics2D g2d baseImage.createGraphics();g2d.drawImage(overlayImage, x, y, null);g2d.dispose();}// 在图片上添加文本支持手动换行文本水平居中private static void addTextToImage(BufferedImage baseImage, String text, Font font, Color color, int maxWidth, int y) {Graphics2D g2d baseImage.createGraphics();g2d.setFont(font);g2d.setColor(color);FontMetrics fm g2d.getFontMetrics();int lineHeight fm.getHeight();int currentY y;String[] lines text.split(\n);for (String line : lines) {int lineWidth fm.stringWidth(line);int lineX (maxWidth - lineWidth) / 2; // 居中g2d.drawString(line, lineX, currentY);currentY lineHeight;}g2d.dispose();} 4、调用方法 public static void main(String[] args) throws Exception {// 1. 读取原始图片BufferedImage image null;try {image ImageIO.read(new File(C:\\Users\\caozhen\\Desktop\\图片素材\\1.png)); // 替换成您的图片路径} catch (IOException e) {e.printStackTrace();}if (image null) {System.err.println(无法读取图片);return;}// 2. 在图片上添加透明的二维码String qrText https://qhdm.mzt.zj.gov.cn:9090/szmp/#/wait?codeb20267e5298948a2bca5de8d4a8081a4typedztimeStrap1694503662057; // 替换成您的二维码文本int qrSize 500; // 二维码尺寸BufferedImage qrCodeImage generateQRCode(qrText, qrSize);int qrX (image.getWidth() - qrSize) / 2;int qrY 1050; // 设置二维码的垂直位置addImageToImage(image, qrCodeImage, qrX, qrY);// 3. 在图片上添加中文文本支持手动换行String chineseText 浙江省湖州市吴兴区妙西镇\n 妙山村下姚166号;Font font new Font(微软雅黑, Font.BOLD, 70); // 替换成所需的字体和大小Color textColor Color.BLACK; // 文本颜色int textX 20; // 文本左侧的边距int textY 800; // 设置文本的垂直位置int textWidth image.getWidth() - 40; // 文本可用的宽度addTextToImage(image, chineseText, font, textColor, textWidth, textY);// 4. 保存带有二维码和文本的图片try {ImageIO.write(image, png, new File(C:\\Users\\caozhen\\Desktop\\图片素材\\output.png)); // 替换成保存的文件路径} catch (IOException e) {e.printStackTrace();}} 5、最终生成的图片成功 三、如何生成透明的二维码 1、生成二维码 // 生成透明的二维码图片private static BufferedImage generateQRCode(String text, int size) {MapEncodeHintType, Object hints new HashMap();hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.CHARACTER_SET, UTF-8);hints.put(EncodeHintType.MARGIN, 0); // 无边距try {QRCodeWriter writer new QRCodeWriter();BitMatrix bitMatrix writer.encode(text, BarcodeFormat.QR_CODE, size, size, hints);int width bitMatrix.getWidth();int height bitMatrix.getHeight();BufferedImage qrImage new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);// 这里就是生成透明二维码关键之处for (int x 0; x width; x) {for (int y 0; y height; y) {qrImage.setRGB(x, y, bitMatrix.get(x, y) ? Color.BLACK.getRGB() : new Color(0, 0, 0, 0).getRGB());}}// 渲染二维码Graphics2D graphics1 qrImage.createGraphics();// 添加蓝色边框int borderSize 10; // 边框大小Color myColor new Color(0x19, 0x76, 0xFF); // 红色graphics1.setColor(myColor);graphics1.fillRect(0, 0, size, borderSize); // 上边框graphics1.fillRect(0, 0, borderSize, size); // 左边框graphics1.fillRect(size - borderSize, 0, borderSize, size); // 右边框graphics1.fillRect(0, size - borderSize, size, borderSize); // 下边框return qrImage;} catch (WriterException e) {e.printStackTrace();return null;}} 2、看看透明二维码结果 四、如何希望生成的是浏览器下载图片 1、 代码调整 1.在方法入参的时候加上HttpServletResponse response// 保存带有二维码和文本的图片// 将图片发送到浏览器response.setContentType(image/png);response.setHeader(Content-Disposition, attachment; filename\output.png\);OutputStream os response.getOutputStream();ImageIO.write(image, png, os);os.close(); 五、完整接口调用流程 1.controller层 RestController RequestMapping(/xxx/user/) Api(value 生成二维码, description 生成二维码) public class QrcodeController {RequestMapping(value /createAddressQrcode, method RequestMethod.POST)public void createAddressQrcode(HttpServletResponse response) throws IOException {ImageFileUtils imageFileUtils new ImageFileUtils();imageFileUtils.createImage(response);}} 2、工具类ImageFileUtils public class ImageFileUtils {public void createImage(HttpServletResponse response) throws IOException {// 1. 读取原始图片BufferedImage image null;try {//这里是读取网络图片URL url new URL(https:xxxxxxxxxxxxxxxxxxxxxxxxxx);image ImageIO.read(url);} catch (IOException e) {e.printStackTrace();}if (image null) {return R.error(无法读取图片);}// 2. 在图片上添加透明的二维码String qrText https:xxxxxxxxxxxxxxxx; // 替换成您的二维码文本int qrSize 500; // 二维码尺寸BufferedImage qrCodeImage generateQRCode(qrText, qrSize);int qrX (image.getWidth() - qrSize) / 2;int qrY 1050; // 设置二维码的垂直位置addImageToImage(image, qrCodeImage, qrX, qrY);// 3. 在图片上添加中文文本支持手动换行String chineseText createQrcodeRequest.getAddress();Font font new Font(微软雅黑, Font.BOLD, 90); // 替换成所需的字体和大小Color textColor Color.BLACK; // 文本颜色int textX 20; // 文本左侧的边距int textY 800; // 设置文本的垂直位置int textWidth image.getWidth() - 40; // 文本可用的宽度addTextToImage(image, chineseText, font, textColor, textWidth, textY);// 4. 保存带有二维码和文本的图片// 将图片发送到浏览器response.setContentType(image/png);response.setHeader(Content-Disposition, attachment; filename\output.png\);OutputStream os response.getOutputStream();ImageIO.write(image, png, os);os.close();}// 生成二维码图片private static BufferedImage generateQRCode(String text, int size) {MapEncodeHintType, Object hints new HashMap();hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.CHARACTER_SET, UTF-8);try {QRCodeWriter writer new QRCodeWriter();BitMatrix bitMatrix writer.encode(text, BarcodeFormat.QR_CODE, size, size, hints);int width bitMatrix.getWidth();int height bitMatrix.getHeight();BufferedImage qrImage new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);Graphics2D graphics qrImage.createGraphics();graphics.setColor(Color.WHITE);graphics.fillRect(0, 0, size, size);graphics.setColor(Color.BLACK);for (int x 0; x size; x) {for (int y 0; y size; y) {if (bitMatrix.get(x, y)) {graphics.fillRect(x, y, 1, 1);}}}// 渲染二维码Graphics2D graphics1 qrImage.createGraphics();// 添加蓝色边框int borderSize 10; // 边框大小Color myColor new Color(0x19, 0x76, 0xFF); // 红色graphics1.setColor(myColor);graphics1.fillRect(0, 0, size, borderSize); // 上边框graphics1.fillRect(0, 0, borderSize, size); // 左边框graphics1.fillRect(size - borderSize, 0, borderSize, size); // 右边框graphics1.fillRect(0, size - borderSize, size, borderSize); // 下边框return qrImage;} catch (WriterException e) {e.printStackTrace();return null;}}// 在图片上添加图片private static void addImageToImage(BufferedImage baseImage, BufferedImage overlayImage, int x, int y) {Graphics2D g2d baseImage.createGraphics();g2d.drawImage(overlayImage, x, y, null);g2d.dispose();}// 在图片上添加文本支持手动换行文本水平居中private static void addTextToImage(BufferedImage baseImage, String text, Font font, Color color, int maxWidth, int y) {Graphics2D g2d baseImage.createGraphics();g2d.setFont(font);g2d.setColor(color);FontMetrics fm g2d.getFontMetrics();int lineHeight fm.getHeight();int currentY y;String[] lines text.split(\n);for (String line : lines) {int lineWidth fm.stringWidth(line);int lineX (maxWidth - lineWidth) / 2; // 居中g2d.drawString(line, lineX, currentY);currentY lineHeight;}g2d.dispose();} } 六、注意事项 就是当程序部署到linux服务器时文字格式没有变化的处理方案 原因就是linux服务器没有微软雅黑字体所以导致没有效果。 解决方案是将windows中微软雅黑字体放到linux服务器下即可。 1、到 C:\windows\fonts 复制对应字体库微软雅黑、宋体、黑体等各文件后缀可能不一样有的为ttf有的为ttc不影响使用。 2、上传刚才复制的字体库到/usr/share/fonts/zh_CN目录下如果没有该目录用命令mkdir /usr/share/fonts/zh_CN  来创建然后再上传。 3、修改字体权限使root以外的用户可以使用这些字体chmod -R 777 /usr/share/fonts/zh_CN使用777 赋予全部权限 4、重启springboot项目即可。 总结 好了以上就是在图片上嵌入二维码和加入文字的代码了 有问题可以在评论区留言或者私信我看到会回复你。
http://www.pierceye.com/news/739598/

相关文章:

  • 网站建设排名北京网站排名降级的原因有哪些
  • 介绍网页设计做seo推广网站
  • 建立个人博客网站wordpress东城东莞网站建设
  • 从哪些方面建设网站泰州东方医院
  • 分类信息网站系统cmsWordPress新闻面包屑主题
  • wordpress 多标签关键字优化策略
  • idea15网站开发网站如何提升seo排名
  • 谁有网站推荐一下好安阳刚刚发生的事
  • 博客网站快速排名临邑县住房和城乡建设局网站
  • 二手网站建设方案营销网站建设服务平台
  • 遵化建设局网站濮阳新闻综合频道
  • 百度云如何做网站论文网站建设与运营
  • 网站开发环境实验报告注册公司流程和费用是多少
  • 下载一个网站学院网站建设的作用
  • 济南专业网站优化花西子的网络营销策略
  • 武城网站建设费用网页设计试题及答案
  • 郑州外贸网站建设公司搜索引擎排名的三大指标
  • 温州专业微网站制作电台 主题 wordpress
  • wordpress做网站过程阳江网上车管所
  • 网站抓取qq上海自贸区注册公司流程
  • 深圳网站设计推荐刻烟台制作网站有哪些
  • 网站注册系统源码卢松松博客源码 wordpress博客模板
  • 网站开发进阶实训报告廊坊安次区网站建设公司
  • jquery插件网站推荐打开网站自动跳转代码
  • 佛山顺德容桂网站制作写作平台
  • 网站源码下载pdf文件品质好房
  • 山网站建设长沙网站开发湖南微联讯点不错
  • 网站建设的方案模板邢台123今天的招聘信息
  • 一个网站做app网站如何做收款二维码
  • 济南seo网站优化网站开发源代码 百度文库