Help. BufferedImage.getGraphics Failed

Comx 2004-08-19 11:44:16
我的部分代码如下
String text = "哇哈哈";
String imageFile = "test.JPG";
String outimage = "out.jpg";
int x = 50;
int y = 50;
String fontColor = "000000";
int fontSize = 20;
String fontStyle = "";
String fontName = "宋体";

OutputStream output=new FileOutputStream(new File(outimage));

if(imageFile.toLowerCase().endsWith(".jpeg")||imageFile.toLowerCase().endsWith(".jpg"))
{

InputStream imageIn = new FileInputStream(new File(imageFile));
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(imageIn);
BufferedImage image = decoder.decodeAsBufferedImage();
Graphics g=image.getGraphics();

但出现以下错误

Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:125)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1031)
at testpic.main(testpic.java:40)

有人知道是什么原因吗?
...全文
118 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
nql10 2004-12-21
  • 打赏
  • 举报
回复
与环境 有关系。
Comx 2004-08-20
  • 打赏
  • 举报
回复
郁闷。还是没有人回答
学以致远~ 2004-08-19
  • 打赏
  • 举报
回复
帮你顶一下
射天狼 2004-08-19
  • 打赏
  • 举报
回复
UP
Comx 2004-08-19
  • 打赏
  • 举报
回复
牟人知道吗?

UP啊~UP
qiuafa 2004-08-19
  • 打赏
  • 举报
回复
u.p.
ecaol 2004-08-19
  • 打赏
  • 举报
回复
up

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧