Java生成png文件字体不清晰_将Graphics2D写入BufferedImage - 字体分辨率较差
因此,我尝试通过绘制BufferedImage中的Graphics2D对象,然后使用ImageIO.write()将其写入文件来创建用于通用目的的标签。不幸的是,我遇到了一个问题,我无法弄清楚如何使字体的质量不被模糊和#39; (我无法想到英文中的单词,边缘有点切割或锯齿状,有点表示我认为渲染分辨率低)。有没有办法设置它,以便字体呈现在某个DPI /质量/分辨率?
/**
*
* @param data Array of Strings passed into label, where data[0] is the string to be barcoded
* @param titles Array of Strings passed into label parallel to data array, containing appropriate titles
* @throws IOException If
* @throws WriterException
*/
public static File createSeedBag(String[] titles,String[] data, Font[] fonts) throws IOException, WriterException{
/**
* TODO: Array of Fonts to customize Font
* Size customization
*/
BufferedImage theLabel;
BufferedImage theBarcode;
Graphics2D theGraphics;
File imageFile,
theFile;
FontMetrics titleMetrics,
theMetrics;
int width = 300;
int height = 450;
theLabel = new BufferedImage(width,height, BufferedImage.TYPE_BYTE_GRAY);
imageFile = LabelPrinter.writeBarCode(data[0], BarcodeSpecs.LARGE);
theGraphics = theLabel.createGraphics();
theGraphics.setPaint(Color.WHITE);
theGraphics.fillRect(0, 0, theLabel.getWidth(), theLabel.getHeight());
theGraphics.setPaint(Color.BLACK);
theGraphics.drawRect(0, 0, theLabel.getWidth()-1, theLabel.getHeight()-1);
/**
* Font objects
*/
fonts[0] = new Font("Bodoni 72", Font.BOLD, 40);
theGraphics.setFont(fonts[0]);
/**
* 1) Read Image File and set to bottom of label
*
* 2)
*/
theBarcode = ImageIO.read(imageFile);
theGraphics.drawImage(theBarcode, 1, height - 61, null);
titleMetrics = theGraphics.getFontMetrics(fonts[0]);
theGraphics.drawString(data[data.length-1], (width/2) - ((titleMetrics.stringWidth(data[data.length-1])) / 2), 50);
fonts[1]= new Font("Bodoni 72",0,20);
theMetrics = theGraphics.getFontMetrics(fonts[1]);
int stringHeight = theMetrics.getAscent();
theGraphics.setFont(fonts[1]);
for(int i = 1; i< data.length; i++) {
theGraphics.drawString(titles[i] + ": " + data[i], 5, 50 + (stringHeight * (i+1)));
}
theFile = new File("currentLabel.png");
ImageIO.write(theLabel, "png", theFile);
imageFile.deleteOnExit();
return theFile;
}
Java生成png文件字体不清晰_将Graphics2D写入BufferedImage - 字体分辨率较差相关推荐
- java 生成word文件怎么打开乱码_打开word文档 乱码弹出文件转换对话框
这类乱码是一般是由于在Windows注册表中,关于字体部分配置不正常造成的,解决方法如下: 方法一:找一台与你的Windows版本相同且显示正常的机器,依下列步骤进行: 1.在正常机器上选择" ...
- Java生成PDF文件_自用
Java生成PDF文件 一.前言 前几天,做ASN条码收货模块,需要实现打印下载收货报表,经一番查找,选定iText--用于生成PDF文档的一个Java类库.废话不多说,进入正题. 二.iText简介 ...
- 超详细的java生成excel文件并下载
在网上随手一搜,可以搜到很多java生成excel文件相关的博客,但每个都有不同,核心点说清楚了,但具体运用的时候,相信大家或多或少都没法一次直接运用,这样每次去找并且运用的时候很费时间,所以这也是我 ...
- POI以SAX方式解析Excel2007大文件(包含空单元格的处理) Java生成CSV文件实例详解...
http://blog.csdn.net/l081307114/article/details/46009015 http://www.cnblogs.com/dreammyle/p/5458280. ...
- # Java 生成pdf文件
Java 生成pdf文件 引入依赖 <!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf --> <depend ...
- zipentry压缩乱码linux,java生成压缩文件 ZipEntry出现乱码的有关问题
java生成压缩文件 ZipEntry出现乱码的问题 在项目中,一次导出的文件有好几个,而且文件内容比较大,最后考虑到把文件进行压缩在下载,开始试用JDK自带的ZIP压缩包时,ZipEntry ze ...
- java流与文件——java生成解压缩文件(夹)
[0]README 0.1) 本文描述转自 http://blog.csdn.net/chenssy/article/details/9622171 , 旨在理解 java流与文件--java生成解压 ...
- java 生成csv文件_Java生成CSV文件实例详解
本文实例主要讲述了java生成csv文件的方法,具体实现步骤如下: 1.新建csvutils.java文件: package com.saicfc.pmpf.internal.manage.utils ...
- Java生成ics文件
java生成ICS文件,这玩意好象是个什么日程表类的东西.可以导入到outlook里面用. public void exportActivityDates(HttpServletRequest req ...
最新文章
- base64 python兼容js_无法在中读取Base64编码的图像节点.js它是从Python发送的
- [0x17基本数据结构-二叉堆]-Supermarket
- 机器人技术推动工业领域的数字革命
- binlog2mysql,MySQL 数据恢复工具之binlog2sql
- 加减法叫做什么运算_小学四则运算基础知识,赶快给孩子存下吧!
- android遥控器按键传输流程,android 海思平台遥控器按键映射流程
- java中final关键字、权限修饰符、内部类(成员内部类、局部内部类、匿名内部类)
- 关于指针int *p=a和*p=a的纠正
- x86软件如何在win32下使用_「译」JVM是如何使用那些你从未听过的x86魔幻指令实现String.compareTo的...
- windows 使用 tricks
- 基于51单片机的指纹考勤器
- 如何使用MySQL Workbench建立数据库
- 1060显卡用什么软件测试,【影驰 GTX 1060 GAMER 显卡使用测试】频率|性能|软件_摘要频道_什么值得买...
- 谦虚的向大家问个技术问题,树型结构的排序问题
- 银行账户模拟java_使用Java模拟银行账户存、取款、转账功能
- UEFI规范驱动模型(二):驱动加载过程
- 不撞南墙不回头-深度优先搜索算法
- js自定义打印网页内容
- html当前窗口打开页面,JavaScript 在本窗口打开网页
- One afternoon in Zhongguancun(redo CC5)