Java生成emf图片

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.io.FileOutputStream;
import java.util.Vector;

import org.freehep.graphicsio.emf.EMFConstants;
import org.freehep.graphicsio.emf.EMFHandleManager;
import org.freehep.graphicsio.emf.EMFOutputStream;
import org.freehep.graphicsio.emf.EMFTag;
import org.freehep.graphicsio.emf.gdi.CreateBrushIndirect;
import org.freehep.graphicsio.emf.gdi.DeleteObject;
import org.freehep.graphicsio.emf.gdi.EMFRectangle;
import org.freehep.graphicsio.emf.gdi.EOF;
import org.freehep.graphicsio.emf.gdi.Ellipse;
import org.freehep.graphicsio.emf.gdi.ExtCreateFontIndirectW;
import org.freehep.graphicsio.emf.gdi.ExtCreatePen;
import org.freehep.graphicsio.emf.gdi.ExtLogFontW;
import org.freehep.graphicsio.emf.gdi.ExtLogPen;
import org.freehep.graphicsio.emf.gdi.ExtTextOutA;
import org.freehep.graphicsio.emf.gdi.ExtTextOutW;
import org.freehep.graphicsio.emf.gdi.GDIComment;
import org.freehep.graphicsio.emf.gdi.LogBrush32;
import org.freehep.graphicsio.emf.gdi.LogFontW;
import org.freehep.graphicsio.emf.gdi.ModifyWorldTransform;
import org.freehep.graphicsio.emf.gdi.Panose;
import org.freehep.graphicsio.emf.gdi.PolyPolygon;
import org.freehep.graphicsio.emf.gdi.SelectObject;
import org.freehep.graphicsio.emf.gdi.SetBkMode;
import org.freehep.graphicsio.emf.gdi.SetMapMode;
import org.freehep.graphicsio.emf.gdi.SetMiterLimit;
import org.freehep.graphicsio.emf.gdi.SetStretchBltMode;
import org.freehep.graphicsio.emf.gdi.SetTextColor;
import org.freehep.graphicsio.emf.gdi.SetViewportExtEx;
import org.freehep.graphicsio.emf.gdi.SetViewportOrgEx;
import org.freehep.graphicsio.emf.gdi.SetWindowExtEx;
import org.freehep.graphicsio.emf.gdi.SetWindowOrgEx;
import org.freehep.graphicsio.emf.gdi.Text;
import org.freehep.graphicsio.emf.gdi.TextA;
import org.freehep.graphicsio.emf.gdi.TextW;

public class FreeTest2 {
public static void main(String[] args) {

try {
Rectangle b = new Rectangle(0, 0, -1, -1);
Vector emf = new Vector<>()

// EMFRectangle rect1 = new EMFRectangle(new Rectangle(435, 427, 900, 141));
// emf.add(rect1);
// EMFRectangle rect2 = new EMFRectangle(new Rectangle(1335, 427, 900, 141));
// emf.add(rect2);

TextW text2 = new TextW(new Point(381, 403), "报销人:", 0, b, new int[] { 18, 18, 18, 18 });
ExtTextOutW w2 = new ExtTextOutW(new Rectangle(0, 0, 0, 0), 1, 1, 1, text2);
emf.add(w2);
TextW text3 = new TextW(new Point(287, 86), "部门:", 0, b, new int[] { 18, 18, 18 });
ExtTextOutW w3 = new ExtTextOutW(new Rectangle(0, 0, 0, 0), 1, 1, 1, text3);
emf.add(w3);
TextW text4 = new TextW(new Point(475, 86), "事由:", 0, b, new int[] { 18, 18, 18 });
ExtTextOutW w4 = new ExtTextOutW(new Rectangle(0, 0, 0, 0), 1, 1, 1, text4);
emf.add(w4);

emf.add(new GDIComment("S

ettings"));
emf.add(new SetMapMode(SetMapMode.MM_ANISOTROPIC));
emf.add(new SetBkMode(SetBkMode.BKG_TRANSPARENT));
emf.add(new SetWindowOrgEx(new Point(0, 0)));
emf.add(new SetViewportOrgEx(new Point(0, 0)));
emf.add(new SetWindowExtEx(new Dimension(2550, 3300)));
emf.add(new SetViewportExtEx(new Dimension(2550, 3300)));
emf.add(new SetStretchBltMode(EMFConstants.COLORONCOLOR));


emf.add(new GDIComment("TextW"));
LogFontW font1 = new LogFontW(-82, 0, 0, 0, 0, false, true, false,0, 3, 2, 1, 0x22, "宋体");
LogFontW font2 = new LogFontW(new Font("宋体",Font.ITALIC, 40));
Panose panose = new Panose();
ExtLogFontW extFont = new ExtLogFontW(font2, "", "", 0, 0, 0, new byte[] {0, 0, 0, 0}, 0, panose);
emf.add(new ExtCreateFontIndirectW(1, extFont));
emf.add(new SelectObject(1));
TextW text = new TextW(new Point(592, 347), "费用报销单", 0, b, new int[] { 60, 60, 60, 60, 60 });
emf.add(new ExtTextOutW(new Rectangle(0,0,100,100), 2, 0, 0, text));
emf.add(new DeleteObject(1));

emf.add(new GDIComment("End"));
emf.add(new EOF());

EMFOutputStream out = new EMFOutputStream(new FileOutputStream("g://image//EMFTest2.emf"), new Rectangle(283, 317, 4550, 3300),
new EMFHandleManager(), "EMFTest2", "TestFile", new Dimension(800, 600));

for (int i = 0; i < emf.size(); i++) {
out.writeTag((EMFTag) emf.get(i));
}
out.close();

} catch (Exception ex) {
ex.printStackTrace();
}
}
}

相关文档
最新文档