【问题标题】:Using SWT on Centos 7 to draw text on a picture在 Centos 7 上使用 SWT 在图片上绘制文本
【发布时间】:2015-10-25 04:06:27
【问题描述】:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.widgets.Display;     

....

display = new Display();
image = new Image(display, chosenImageFilePath);
gc = new GC(image);
gc.drawText("text to be drawn", 0, 0, SWT.DRAW_TRANSPARENT);    

gc.dispose();
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData() };
loader.save(destinationImageFilePath, SWT.IMAGE_JPEG);

image.dispose();
display.dispose();

我在图片上画了一些文字,这一切都可以在使用 Eclipse 的 Windows 上运行。当我将其导出为可运行的 jar 并通过 cmd 运行时,它也可以工作。

制作这个程序的主要目的是为了让我可以在我现在在 Centos 7 云服务器上运行的网络应用程序(tomcat、java、jsp、mysql)中使用它。 尝试运行时出现此错误:

Error I get (image)

我已经下载了 swt-3.6.1-gtk-linux-x86_64 并将其添加到 eclipse 的项目库和构建路径中,但它似乎没有修复它。 有任何想法吗?我什至可以在没有显卡的虚拟服务器上运行它吗? PS 我没有展示我的大部分代码(它有效且不会导致错误),它只是计算文本将在图片上绘制的位置。

【问题讨论】:

    标签: java graphics swt centos7


    【解决方案1】:

    回答我自己的问题。好吧,那么……

    1.将此.jar导入项目的构建路径:

        org.eclipse.swt.gtk.linux.x86_64-4.3.jar
    
    1. 使用

      yum install xorg-11-server-Xvfb
      

    我已经启用了虚拟缓冲区的使用来代替缺乏图形环境。

    1. 下一步是激活虚拟显示器:

      Xvfb :1 -ac -screen 0 1024x768x8 & export DISPLAY=:1
      

    然后我就可以运行我的可运行 jar。

    PS 也许没有以最好的方式解释某些事情,但这些是使我能够使用我的应用程序的步骤。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 2014-08-06
      • 2017-07-07
      • 1970-01-01
      • 2010-10-25
      • 1970-01-01
      相关资源
      最近更新 更多