Generate JPG files directly with Java command operation

zhaozj2021-02-08  348

/ ** * Jerugraphics V 1.0 ** See some dynamically generated images is completed, * and the program is very long, I don't think it is very good, regardless of practicality or readability. * Here is the paragraph code, the command line generates an image file. Is this easy to use? * * Create a BufferedImage object, put your "painting" in this buffer, * Open a file, enter the image stream, enter this file, this will have a * JPG file appears, try it. . . * * Mender: * jeru liu * Home: * http://javaren.126.com* email: jeru@163.net * * This is just a sample program, no practical, but it is very reference value.

* / import java.io. *; import java.util. *; import com.sun.image.codec.jpeg. *; import java.awt.image. *; import java.awt. *; public class jerugraphics { BufferedImage image; // Create a jpg file to the specified path public void createJpg (String path) {try {FileOutputStream fos = new FileOutputStream (path); BufferedOutputStream bos = new BufferedOutputStream (fos); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (bos); Encoder.encode (image); bos.close ();} catch (filenotfoundexception fnfe) {system.out.println (fnfe);} catch (ooexception ie) {system.out.println (IOE);}} public static void Main (String [] args) {int width = 400, Height = 200; int XLength = 300, YLENGTH = 150; int count = 5; Vector data = new vector (); data.addelement (new integer (100)); Data.addelement (New Integer (120)); Data.AddeElement (New Integer (New Integer (40)); Data.AddeElement (New Integer (5)); Jerugraphics JG = New Jerugraphics ); Jg.Image = new bufferedimage (width, height, bufferedimage.type_int_rgb); graphics g = jg.image.getgraphics (); // painting g.SetColor (color.White); g.fillRect (0, 0, width, Height); g.SetColor (color.blue); g.drawline (10, Height-10, 10, Height-10-Ylength); g.drawline (10, HEIGHT-10, 10 XLENGTH, HEIGHT-10); // Connection Int YTO; INT YFROM = ((Integer)))). INTVALUE (); for (INT i = 1; i

转载请注明原文地址:https://www.9cbs.com/read-944.html

New Post(0)