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框架 适用与window下java窗口开发~~~~
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 table 实现换行
swt资源释放问题,详细介绍swt如何释放屏幕资源
swt 官方源码以及jar包 使用方法可参照 http://www.eclipse.org/swt/eclipse.php 简单说就是可以直接当项目来导入,源码在src.zip中,关联后即可查看
SWT Table 单元格编辑实例代码
swt高级密笈源码swt高级密笈源码swt高级密笈源码