savefileasimg.java

来自「用JAVA编写的绘图程序 功能简介: 支持存储」· Java 代码 · 共 79 行

JAVA
79
字号
package drawsmart.itsv.image;

import java.io.File;
import drawsmart.itsv.framework.JDSDesktopface;
import drawsmart.itsv.FrameSwing;
import drawsmart.itsv.framework.JDSComponentface;
import drawsmart.itsv.framework.JDSLineface;
import java.awt.Font;
import drawsmart.itsv.tool.GetResource;
import drawsmart.itsv.swing.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class SaveFileAsImg {
  public SaveFileAsImg() {
  }

  public boolean saveFile(JDSDesktopface jDSDesktopface, File file) {
    return saveFile(jDSDesktopface, file, "jpg", null);
  }
  public boolean saveFile(JDSDesktopface jDSDesktopface, File file,String ext,FrameSwing mainFrame) {
    boolean bl = true;

    //开始绘制图形
    try
    {
      int w = Integer.parseInt(GetResource.getXMLResource("imagew"));
      int h = Integer.parseInt(GetResource.getXMLResource("imageh"));
      ExportToImg exportToImg1 = new ExportToImg(w, h, file, ext, mainFrame);
      //绘制线条

      JDSLineface[] jDSLinefaces = jDSDesktopface.getJDSAllLineface();
      for (int i = 0; i < jDSLinefaces.length; i++) {
        exportToImg1.drawLine( (int) (jDSLinefaces[i].getStartPoint().getX()),
                              (int) (jDSLinefaces[i].getStartPoint().getY()),
                              (int) (jDSLinefaces[i].getEndPoint().getX()),
                              (int) (jDSLinefaces[i].getEndPoint().getY()),3);
      }
      //绘制方形
      JDSComponentface[] jDSComponentfaces = jDSDesktopface.getJDSAllComponent();
      for (int i = 0; i < jDSComponentfaces.length; i++) {
        if (!jDSComponentfaces[i].getTextInfo().equals(""))
        {
          exportToImg1.draw(jDSComponentfaces[i].getShape(),
                                jDSComponentfaces[i].getFrameColor(),
                                jDSComponentfaces[i].getFillColor(),
                                jDSComponentfaces[i].getTextInfo(),
                                new Font("Dialog", 14, 14),4);
        }
        else
        {
          exportToImg1.draw(jDSComponentfaces[i].getShape(),
                              jDSComponentfaces[i].getFrameColor(),
                              jDSComponentfaces[i].getFillColor(),4);

        }

      }
      exportToImg1.close();

    }
    catch(Exception e)
    {
      bl=false;
      e.printStackTrace();
    }

    return bl;
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?