免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 1559 | 回复: 13
打印 上一主题 下一主题

如何让 程序 不检测 图形界面是否启动 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-04-27 22:38 |只看该作者 |倒序浏览
java  图像处理

客户端  windows      服务器端 redhat linux   

服务器将 客户端的图片 缩放。然后保存。

提示错误:  

Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable



图形处理 程序没有问题,单机在 windows下  和 linux下 测试都可以通过


可能的原因是 服务器没有启动 图形界面导致 问题发生。

请问怎么解决, 怎么不让 java 寻找 linux 图形界面是否启动。

怎么样作才能不让 java 检测图形界面是否启动。

据说可以在 /etc/profile  下面加入:

java -Djava.awt.headless=true

这句话这么加入 对吗 ?

应该怎么加入 ?

论坛徽章:
0
2 [报告]
发表于 2004-04-28 08:55 |只看该作者

如何让 程序 不检测 图形界面是否启动

不是加在/etc/profile里,而是说你启动你的程序的时候加上-Djava......
http://forum.java.sun.com/thread.jsp?forum=20&thread=132877

论坛徽章:
0
3 [报告]
发表于 2004-04-28 20:25 |只看该作者

如何让 程序 不检测 图形界面是否启动

老哥:   我这里不能打开 外国的网站

          你能不能帮我看看呀 !


谢谢了!

论坛徽章:
0
4 [报告]
发表于 2004-04-28 21:44 |只看该作者

如何让 程序 不检测 图形界面是否启动

我像上面那样做了还是不对  请问怎么回事 /?

论坛徽章:
0
5 [报告]
发表于 2004-04-28 21:47 |只看该作者

如何让 程序 不检测 图形界面是否启动

我没有试验过,只是看到有这么一个看上去正规一点的讨论。具体的我没有作试验。

论坛徽章:
0
6 [报告]
发表于 2004-05-01 05:21 |只看该作者

如何让 程序 不检测 图形界面是否启动

问题解决了!

关键是 java 图像处理 学要 图形界面环境。

当然我作得是 b/s 结构得,不可能再服务器 上启动 图形环境。

后在我在 web 服务器 启动配置 文件里面 加上了 哪个参数就好了 !
谢谢大家关心!

论坛徽章:
0
7 [报告]
发表于 2004-05-01 09:04 |只看该作者

如何让 程序 不检测 图形界面是否启动

鼓励象top123一样解决问题后把解决方法贴上来的朋友!

论坛徽章:
0
8 [报告]
发表于 2004-05-05 14:21 |只看该作者

如何让 程序 不检测 图形界面是否启动

呵呵!

感谢斑竹 的肯定!

同时希望每个人都能成长起来!

论坛徽章:
0
9 [报告]
发表于 2004-05-05 14:23 |只看该作者

如何让 程序 不检测 图形界面是否启动

java 图像处理

客户端 windows 服务器端 redhat linux

服务器将 客户端的图片 缩放。然后保存。
~~~~~~~~~~~~~~~~~~~~~~~这个用ImageMagick不行么?

论坛徽章:
0
10 [报告]
发表于 2004-05-05 14:30 |只看该作者

如何让 程序 不检测 图形界面是否启动

ImageMagick   ?

是不是那个 需要在 服务器端安装 新.dll  或者要进行 本地调用的那种?

我没有用过,不懂。

我得源程序 :





import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;

// com.sun.image.codec.jpeg package is included in sun and ibm sdk 1.3
import com.sun.image.codec.jpeg.*;

/**
* Use this class to size images.
*
* @author Dan Becker
*/
public class ImageSizer {
        public static final MediaTracker tracker = new MediaTracker( new Component() {} );
   /** Adjusts the size of the image to the given coordinates.
     * If width or height is -1, the image aspect ration is maintained.
     */
   public static Image setSize( Image image, int width, int height ) {
      return setSize( image, width, height, java.awt.Image.SCALE_DEFAULT );
   } // setSize

   /** Adjusts the size of the image to the given coordinates.
     * If width or height is -1, the image aspect ration is maintained.
     * <p>;
     * Hints are one of SCALE_DEFAULT, SCALE_FAST, SCALE_SMOOTH,
     * SCALE_REPLICATE, SCALE_AREA_AVERAGING as defined in java.awt.Image.
     */
   public static Image setSize( Image image, int width, int height, int hints ) {
      return image.getScaledInstance( width, height, hints );
   } // setSize

   /** Checks the given image for valid width and height. */
   public static void checkImage( Image image ) {
      waitForImage( image );
      int imageWidth = image.getWidth( null );
      if ( imageWidth < 1 )
         throw new IllegalArgumentException( "image width " + imageWidth + " is out of range" );
      int imageHeight = image.getHeight( null );
      if ( imageHeight < 1 )
         throw new IllegalArgumentException( "image height " + imageHeight + " is out of range" );
      // System.out.println( "Image size=" + imageWidth + "x" + imageHeight );
   } // checkImage

   /** Waits for given image to load. Use before querying image height/width/colors. */
   public static void waitForImage( Image image ) {
      try {
         tracker.addImage( image, 0 );
         tracker.waitForID( 0 );
         // loadStatus = tracker.statusID( 0, false );
         tracker.removeImage(image, 0);
      } catch( InterruptedException e ) { e.printStackTrace(); }
   } // waitForImage

   /** Encodes the given image at the given quality to the output stream. */
   public static void encodeJPEG( OutputStream outputStream, Image outputImage, float outputQuality )
      throws java.io.IOException {
      int outputWidth  = outputImage.getWidth( null );
      if ( outputWidth < 1 )
         throw new IllegalArgumentException( "output image width " + outputWidth + " is out of range" );
      int outputHeight = outputImage.getHeight( null );
      if ( outputHeight < 1 )
         throw new IllegalArgumentException( "output image height " + outputHeight + " is out of range" );

      // Get a buffered image from the image.
      BufferedImage bi = new BufferedImage( outputWidth, outputHeight,
         BufferedImage.TYPE_INT_RGB );                                                   
      Graphics2D biContext = bi.createGraphics();
      biContext.drawImage( outputImage, 0, 0, null );
      // Note that additional drawing such as watermarks or logos can be placed here.

      // com.sun.image.codec.jpeg package is included in sun and ibm sdk 1.3
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( outputStream );
      // The default quality is 0.75.
      JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam( bi );
      jep.setQuality( outputQuality, true );
      encoder.encode( bi, jep );
      // encoder.encode( bi );
      outputStream.flush();      
   } // encodeImage

   /** Test program */
   public static void main( String [] args )
      throws java.io.IOException {
      if (args.length < 4) {
         System.out.println( "ImageSizer - changes the size of an image." );
         System.out.println( "use: java ImageSizer inputFile outputFile outputWidth outputQuality" );
         return;
      }
      // Gather input arguments.
      String inputFileName = args[ 0 ];
      String outputFileName = args[ 1 ];
      int outputWidth = Integer.parseInt( args[ 2 ] );
      if ( outputWidth < 1 )
         throw new IllegalArgumentException( "output width \"" + args[ 2 ] +"\" out of range" );
      float outputQuality = Float.parseFloat( args[ 3 ] );
      if (( outputQuality < 0.0F ) || ( outputQuality >; 1.0F ))
         throw new IllegalArgumentException( "output quality \"" + args[ 3 ] +"\" out of range" );

      // Get input image
      Image inputImage = Toolkit.getDefaultToolkit().getImage( inputFileName );
      checkImage( inputImage );
      // System.out.println( "Input image size=" + inputImage.getWidth( null ) + "x" + inputImage.getHeight( null ) );

      // Create output image.
      Image outputImage = ImageSizer.setSize( inputImage, outputWidth, -1 );
      checkImage( outputImage );
      // System.out.println( "Output image size=" + outputImage.getWidth( null ) + "x" + outputImage.getHeight( null ) );

      // Encode JPEG file.
      FileOutputStream fos = new FileOutputStream( outputFileName );
      encodeJPEG( fos, outputImage, outputQuality );
      fos.close();
      // For some reason, the MediaTracker/ImageProducer likes to hang on.
      System.exit( 0 );
   } // main
} // class ImageSizer


很简单的, 关于上传 使用了 jspsamrtupload 组建!

这个程序是本地的,注意路径问题就可以了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP