When generate a image for Chinese character, if your computer has no song ti font style, should read a system file to load the font style.
find following file.
C:\WINDOWS\Fonts\simsun.ttc
Coding as follows:
Font ttfFont = Font.createFont(Font.TRUETYPE_FONT, new File("C:\WINDOWS\Fonts\simsun.ttc"));
Font ttfReal = ttfFont.deriveFont(Font.PLAIN, 12);
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setBackground(Color.YELLOW);
g2.clearRect(0, 0, width, height);
g2.setPaint(Color.BLACK);
FontRenderContext context = g2.getFontRenderContext();
Rectangle2D bounds = ttfReal.getStringBounds(name, context);
double x = (width - bounds.getWidth()) / 2;
double y = (height - bounds.getHeight()) / 2;
double ascent = -bounds.getY();
double baseY = y + ascent;
g2.setFont(ttfReal);
g2.drawString(name, (int) x, (int) baseY);
分享到:
相关推荐
SWT配置 SWT配置 SWT配置 SWT配置 SWT配置 SWT配置 SWT配置 SWT配置
NULL 博文链接:https://gxblluojialin.iteye.com/blog/2028156
64位windows操作系统使用的SWT库
org.eclipse.swt.graphics.Font.class org.eclipse.swt.graphics.FontData.class org.eclipse.swt.graphics.FontMetrics.class org.eclipse.swt.graphics.GC.class org.eclipse.swt.graphics.GCData.class org....
swt工具文档 swt工具文档 swt工具文档 swt工具文档 swt工具文档 swt工具文档
SWT examples,SWT官方例子:http://www.eclipse.org/swt/examples.php 该页面所要下载的例子 其中,swt的例子在\plugins\org.eclipse.swt.examples.source_3.7.0.v3740f.jar中
下载编译的SWT库,版本号4.911,包含多个版本: org.eclipse.swt.cocoa.macosx.x86_64 org.eclipse.swt.gtk.linux.aarch64 org.eclipse.swt.gtk.linux.arm org.eclipse.swt.gtk.linux.ppc64le org.eclipse.swt.gtk....
SWT插件中文教程SWT常用方法SWT插件中文教程SWT常用方法SWT插件中文教程SWT常用方法SWT插件中文教程SWT常用方法SWT插件中文教程SWT常用方法SWT插件中文教程SWT常用方法
swt 基础教程 swt 基础教程 swt 基础教程swt 基础教程swt 基础教程
swt教程 有关SWT怎么应用
SWT官方api文档 开发基于swt的GUI程序必备手册
swt.jar swt.jar swt.jar swt.jar swt.jar
swt-api java swt GUI java界面编程,swt的开发DOC,谁用谁知道,一般人我不告诉他
swt table 实现换行
swt 画图小程序 自由画线 矩形。。import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseMoveListener; ...
swt框架 适用与window下java窗口开发~~~~
swt资源释放问题,详细介绍swt如何释放屏幕资源
swt 官方源码以及jar包 使用方法可参照 http://www.eclipse.org/swt/eclipse.php 简单说就是可以直接当项目来导入,源码在src.zip中,关联后即可查看
SWT Table 单元格编辑实例代码
swt高级密笈源码swt高级密笈源码swt高级密笈源码