sakulagi 回复于:2004-04-28 08:55:54 |
不是加在/etc/profile里,而是说你启动你的程序的时候加上-Djava...... http://forum.java.sun.com/thread.jsp?forum=20&thread=132877 |
top123 回复于:2004-04-28 20:25:14 |
老哥: 我这里不能打开 外国的网站 你能不能帮我看看呀 ! 谢谢了! |
top123 回复于:2004-04-28 21:44:40 |
我像上面那样做了还是不对 请问怎么回事 /? |
sakulagi 回复于:2004-04-28 21:47:35 |
我没有试验过,只是看到有这么一个看上去正规一点的讨论。具体的我没有作试验。 |
top123 回复于:2004-05-01 05:21:56 |
问题解决了! 关键是 java 图像处理 学要 图形界面环境。 当然我作得是 b/s 结构得,不可能再服务器 上启动 图形环境。 后在我在 web 服务器 启动配置 文件里面 加上了 哪个参数就好了 ! 谢谢大家关心! |
sakulagi 回复于:2004-05-01 09:04:02 |
鼓励象top123一样解决问题后把解决方法贴上来的朋友! |
top123 回复于:2004-05-05 14:21:17 |
呵呵! 感谢斑竹 的肯定! 同时希望每个人都能成长起来! |
酷于 回复于:2004-05-05 14:23:18 |
java 图像处理 客户端 windows 服务器端 redhat linux 服务器将 客户端的图片 缩放。然后保存。 ~~~~~~~~~~~~~~~~~~~~~~~这个用ImageMagick不行么? |
top123 回复于:2004-05-05 14:30:38 |
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 组建! 这个程序是本地的,注意路径问题就可以了! |
酷于 回复于:2004-05-05 14:36:15 |
我不懂Java,不过我觉得如果要实现在服务器端"缩放图像" 用ImageMagick足够了,而且不用C-S结构```` |
top123 回复于:2004-05-05 14:38:14 |
呵呵 ! 这个正好是 B/s 结构的! 不用 java , 其他的方法我不懂, 据说 比java 好用! |
酷于 回复于:2004-05-05 14:46:18 |
写个在服务器端生成"缩略图"的脚本,嗯,原创阿``` [code:1:42eaab29c0] #!/usr/bin/perl $identify= "/usr/local/ImageMagick/bin/identify"; $convert= "/usr/local/ImageMagick/bin/convert"; $composite= "/usr/local/ImageMagick/bin/composite"; $convdir= "./pics"; #源路径 $objcdir= "./picd"; #目标路径 $tmp= "/tmp/.conv.tmp"; $white= "/root/white.jpg"; opendir(OD,$convdir); @allds=readdir OD; closedir OD; foreach $alldf(@allds){ if($alldf ne "." && $alldf ne ".."){ system("$convert $convdir/$alldf -resize 100x100 $tmp"); open(SO,"$identify $tmp|"); $allso=<SO>; close SO; @alls=split(/ +/,$allso); @wh=split(/x/,$alls[2]); $wh[1]=~s/\+[0-9]//g; if($wh[0]>$wh[1]){ $offset=(100-$wh[1])/2; system("$composite -geometry +0+$offset $tmp $white $objcdir/$alldf"); }else{ $offs=(100-$wh[0])/2; system("$composite -geometry +$offset+0 $tmp $white $objcdir/$alldf"); } } } [/code:1:42eaab29c0] 这段代码的作用,是把"源路径"里的所有图片,转换成不大于100x100的缩略图片,然后加上背景(white.jpg),保存在"目标路径里" 呵呵,强大吧``` |
ginf 回复于:2004-06-02 12:44:00 |
top123大哥,能具体说一下是在web启动环境哪里吗? 假如我是用的tomcat5,是在startup.sh里吗? |