Java generates a JPEG image file. The code is as follows:
My code mainly provides my own workflow designer object use (EWorkflowControl EWF), EWORKFlowControl inherits JComponent overloaded the method of drawing, if you need this feature, you only need to replace EWORKFLOWCONTROL Your own JComponent object.
/ ** Generate a JPEG image file on the graphics on the currently entered workflow object.
* Each node corresponds to a picture.
* The established file is stored under the JAR file folder and created a subfolder
* The name of the folder with the name of the node.
* @Param EWF Requires the workflow object of the JPEG image file.
* @Return Boolean: Returns a Boolean value indicating whether it is saved.
* /
Public Static Boolean BuildthePictrue (EWorkflowControl EWF)
{
// modify by MW
// list all the Node nodes in the process.
// Set these nodes to select the status, and store the picture (the name of the node)
Inode rootnode = EWF.GETNOTE (); Rectangle Bounds = EWF.GETBOUNDS ();
Inode.GetNodeChildren ();
INT Childrenlen = rootnode.getnodechildcount ();
String nodenumber = null;
Boolean flag = true;
/ / Eliminate all nodes to select the status.
For (int J = 0; j Children [J] .SetSelect (false); / / Generate a total map (I am an image of a node) Try { Java.awt.image.bufferedimage image; image = new java.awt.image.bufferedimage (bounds.width, bounds.height, java.awt.image.bufferedImage.type_int_rgb); Graphics g = image.getgraphics (); g.setcolor (color.white); G.fillRect (0, 0, bounds.width, bounds.height); EWF.PaintComponent (g); String path = system.getProperty ("user.dir") system.getProperty ("file.separator") EWF.GetWorkflowName () "[" ewf.getworkflowcode () "]"; File fd = new file (path); IF (! fd.exiss ()) { fd.mkdirs (); } String filepath = path system.getProperty ("file.separator") "0.jpeg"; File Imgfile = New File (FilePath); FileOutputStream Fos = New FileOutputStream (Imgfile); Bufferedoutputstream Bos = New BufferedoutputStream (FOS); JPEGIMAGEENCODER ENCODER = JPEGCODEC.CREATEJPEGENCODER (BOS); Encoder.Encode (image); bos.close (); } Catch (Exception EX) { Flag = false; } // This first image has been generated! // Cycle generate pictures For (int i = 0; i { Nodenumber = Children [i] .Getnodenumber (); IF (nodenumber == null) { Flag = false; continue; } else { Children [i] .SetSelect (TRUE); Try { Java.awt.image.bufferedimage image; image = new java.awt.image.bufferedimage (bounds.width, bounds.height, java.awt.image.bufferedImage.type_int_rgb); Graphics g = image.getgraphics (); g.setcolor (color.white); G.fillRect (0, 0, bounds.width, bounds.height); EWF.PaintComponent (g); String path = system.getProperty ("user.dir") system.getProperty ("file.separator") EWF.GetWorkflowName () "[" ewf.getworkflowcode () "]"; File fd = new file (path); IF (! fd.exiss ()) { fd.mkdirs (); } String filepath = path system.getProperty ("file.separator") nodenumber ". JPEG"; File Imgfile = New File (FilePath); FileOutputStream Fos = New FileOutputStream (Imgfile); BufferedoutputStream Bos = New BufferedoutputStream (FOS); JPEGIMAGEENCODER Encoder = JPEGCODEC.CREATEJPEGENCODER (BOS) Encoder.encode (image); bos.close (); Children [i] .SetSelect (false); } catch (exception ex) { Flag = false; }}} IF (flag) { New ExceptionDialog (pic_save_ok, pic_save_dialog_title, desktopframe.getcurrentInstance (), true) .SetVisible (TRUE); } else { New ExceptionDialog (Pic_save_ERROR, PIC_SAVE_DIALOG_TITLE, DesktopFrame.getCurrentInstance (), true) .SetVisible (TRUE); } Return flag; }