如何生成wmf格式的文件?

社区

C# 帖子详情 如何生成wmf格式的文件? wang0511 2006-01-21 04:20:41 wmf格式如下:

.wmf metafile format

a metafile for the microsoft windows operating system consists of a collection of graphics device interface (gdi) functions that describe an image. because metafiles take up less space and are more device-independent than bitmaps, they provide convenient storage for images that appear repeatedly in an application or need to be moved from one application to another. to generate a metafile, a windows application creates a special device context that sends gdi commands to a file or memory for storage. the application can later play back the metafile and display the image. during playback, windows breaks the metafile down into records and identifies each object with an index to a handle table. when a meta_deleteobject record is encountered during playback, the associated object is deleted from the handle table. the entry is then reused by the next object that the metafile creates. to ensure compatibility, an application that explicitly manipulates records or builds its own metafile should manage the handle table in the same way. for more information on the format of the handle table, see the handletable structure.

in some cases, there are two variants of a metafile record, one representing the record created by windows versions before 3.0 and the second representing the record created by windows versions 3.0 and later. windows versions 3.0 and later play all metafile versions but store only 3.0 and later versions. windows versions earlier than 3.0 do not play metafiles recorded by windows versions 3.0 and later.

a metafile consists of two parts: a header and a list of records. the header and records are described in the remainder of this topic. for a list of function-specific records, see metafile records.

metafile header

the metafile header contains a description of the size of the metafile and the number of drawing objects it uses. the drawing objects can be pens, brushes, bitmaps, or fonts.

the metafile header has the following form:

typedef struct tagmetaheader {

word mttype;

word mtheadersize;

word mtversion;

dword mtsize;

word mtnoobjects;

dword mtmaxrecord;

word mtnoparameters;

} metaheader;

following are the members in the metafile header:

mttype specifies whether the metafile is stored in memory or recorded in a file. this member has one of the following values:

value meaning

0 metafile is in memory.

1 metafile is in a file.

mtheadersize specifies the size, in words, of the metafile header.

mtversion specifies the windows version number. the version number for windows version 3.0 and later is 0x300.

mtsize specifies the size, in words, of the file.

mtnoobjects specifies the maximum number of objects that can exist in the metafile at the same time.

mtmaxrecord specifies the size, in words, of the largest record in the metafile.

mtnoparameters not used.

typical metafile record

the graphics device interface stores most of the gdi functions that an application can use to create metafiles in typical records.

a typical metafile record has the following form:

struct {

dword rdsize;

word rdfunction;

word rdparm[];

}

following are the members in a typical metafile record:

rdsize specifies the size, in words, of the record.

rdfunction specifies the function number. this value may be the number of any function in the table at the end of this section.

rdparm identifies an array of words containing the function parameters (listed in the reverse order in which they are

passed to the function).

following are the gdi functions found in typical records, along with their hexadecimal values:

gdi function value

arc 0x0817

chord 0x0830

ellipse 0x0418

excludecliprect 0x0415

floodfill 0x0419

intersectcliprect 0x0416

lineto 0x0213

moveto 0x0214

offsetcliprgn 0x0220

offsetviewportorg 0x0211

offsetwindoworg 0x020f

patblt 0x061d

pie 0x081a

realizepalette (3.0 and later) 0x0035

rectangle 0x041b

resizepalette (3.0 and later) 0x0139

restoredc 0x0127

roundrect 0x061c

savedc 0x001e

scaleviewportext 0x0412

scalewindowext 0x0400

setbkcolor 0x0201

setbkmode 0x0102

setmapmode 0x0103

setmapperflags 0x0231

setpixel 0x041f

setpolyfillmode 0x0106

setrop2 0x0104

setstretchbltmode 0x0107

settextalign 0x012e

settextcharacterextra 0x0108

settextcolor 0x0209

settextjustification 0x020a

setviewportext 0x020e

setviewportorg 0x020d

setwindowext 0x020c

setwindoworg 0x020b

...全文

964 10 打赏 收藏 如何生成wmf格式的文件? wmf格式如下: .wmf metafile format a metafile for the microsoft windows operating system consists of a collection of graphics device interface (gdi) functions that describe an image. because metafiles take up less space and are more device-independent tha 复制链接

扫一扫 分享 转发到动态 举报 AI 作业

写回复 配置赞助广告取 消

确 定

用AI写文章 10 条回复 切换为时间正序 请发表友善的回复… 发表回复 打赏红包 需支付: 0.00 元 取 消 确 定 Optione 2006-03-06 打赏举报 回复 出去交电费去了/. Optione 2006-03-06 打赏举报 回复 试试这样

private void TestMetafile()

{

Image img = Image.FromFile("H:\\jl.jpg");

Graphics grfx = CreateGraphics();

IntPtr ipHdc = grfx.GetHdc();

Metafile mf = new Metafile(ipHdc, EmfType.EmfPlusDual);

grfx.ReleaseHdc(ipHdc);

grfx.Dispose();

Graphics grfxMeta = Graphics.FromImage(mf);

grfxMeta.DrawImage(img,0,0);

grfxMeta.Dispose();

mf.Save("c:\\1.wmf");

mf.Dispose();

img.Dispose();

}

这是官方文档例子

using System;

using System.Drawing;

using System.Drawing.Imaging;

using System.Windows.Forms;

// for Marshal.Copy

using System.Runtime.InteropServices;

public class Form1 : Form

{

private Metafile metafile1;

private Graphics.EnumerateMetafileProc metafileDelegate;

private Point destPoint;

public Form1()

{

metafile1 = new Metafile(@"C:\Test.wmf");

metafileDelegate = new Graphics.EnumerateMetafileProc(MetafileCallback);

destPoint = new Point(20, 10);

}

protected override void OnPaint(PaintEventArgs e)

{

e.Graphics.EnumerateMetafile(metafile1, destPoint, metafileDelegate);

}

private bool MetafileCallback(

EmfPlusRecordType recordType,

int flags,

int dataSize,

IntPtr data,

PlayRecordCallback callbackData)

{

byte[] dataArray = null;

if (data != IntPtr.Zero)

{

// Copy the unmanaged record to a managed byte buffer

// that can be used by PlayRecord.

dataArray = new byte[dataSize];

Marshal.Copy(data, dataArray, 0, dataSize);

}

metafile1.PlayRecord(recordType, flags, dataSize, dataArray);

return true;

}

static void Main()

{

Application.Run(new Form1());

}

} Optione 2006-03-06 打赏举报 回复 你应该去看看这个文章

http://www.codeproject.com/vcpp/gdiplus/saveasemfexiwmf.asp wang0511 2006-03-06 打赏举报 回复 我顶 wang0511 2006-01-24 打赏举报 回复 这样生成的还是位图,缩放后还是会失真! MonkWang 2006-01-24 打赏举报 回复 学习 帮顶 aSalt 2006-01-24 打赏举报 回复 帮顶 wang0511 2006-01-24 打赏举报 回复 有一个奇怪的问题在C++用CMetaFileDC生成的WMF格式的图,用freehand打不开?而freehand是可以打开其它的wmf文件的! lookfeng 2006-01-23 打赏举报 回复 Bitmap b;

...

b.save(filename, System.Drawing.Imaging.ImageFormat.Wmf); wang0511 2006-01-21 打赏举报 回复

placeable windows metafiles

a placeable windows metafile is a standard windows metafile that has an additional 22-byte header. the header contains information about the aspect ratio and original size of the metafile, permitting applications to display the metafile in its intended form.

the header for a placeable windows metafile has the following form:

typedef struct {

dword key;

handle hmf;

rect bbox;

word inch;

dword reserved;

word checksum;

} metafileheader;

following are the members of a placeable metafile header:

key specifies the binary key that uniquely identifies this file type. this member must be set to 0x9ac6cdd7l.

hmf unused; must be zero.

bbox specifies the coordinates of the smallest rectangle that encloses the picture. the coordinates are in metafile units

as defined by the inch member.

inch specifies the number of metafile units to the inch. to avoid numeric overflow, this value should be less than 1440.

most applications use 576 or 1000.

reserved unused; must be zero.

checksum specifies the checksum. it is the sum (using the xor operator) of the first 10 words of the header.

the actual content of the windows metafile immediately follows the header. the format for this content is identical to that for standard windows metafiles. for some applications, a placeable windows metafile must not exceed 64k.

note: placeable windows metafiles are not compatible with the getmetafile function. applications that intend to use the metafile functions to read and play placeable windows metafiles must read the file by using an input function (such as _lread), strip the 22-byte header, and create a standard windows metafile by using the remaining bytes and the setmetafilebits function.

guidelines for windows metafiles

to ensure that metafiles can be transported between different computers and applications, any application that creates a metafile should make sure the metafile is device-independent and sizable.

the following guidelines ensure that every metafile can be accepted and manipulated by other applications:

set a mapping mode as one of the first records. many applications, including ole applications, only accept metafiles that are in mm_anisotropic mode.

call the setwindoworg and setwindowext functions. do not call the setviewportext or setviewportorg functions if the user will be able to resize or change the dimensions of the object.

use the mfcomment printer escape to add comments to the metafile.

rely primarily on the functions listed in typical metafile record. observe the following limitations on the functions you use:

do not use functions that retrieve data (for example, getactivewindow or enumfontfamilies).

do not use any of the region functions (because they are device dependent).

use stretchblt or stretchdib instead of bitblt.

sample of metafile program output

this section describes a sample program and the metafile that it creates. the sample program creates a small metafile that draws a purple rectangle with a green border and writes the words "hello people" in the rectangle.

makeametafile(hdc)

hdc hdc;

{

hpen hmetagreenpen;

hbrush hmetavioletbrush;

hdc hdcmeta;

handle hmeta;

/* create the metafile with output going to the disk. */

hdcmeta = createmetafile( (lpstr) "sample.met");

hmetagreenpen = createpen(0, 0, (dword) 0x0000ff00);

selectobject(hdcmeta, hmetagreenpen);

hmetavioletbrush = createsolidbrush((dword) 0x00ff00ff);

selectobject(hdcmeta, hmetavioletbrush);

rectangle(hdcmeta, 0, 0, 150, 70);

textout(hdcmeta, 10, 10, (lpstr) "hello people", 12);

/* we are done with the metafile. */

hmeta = closemetafile(hdcmeta);

/* play the metafile that we just created. */

playmetafile(hdc, hmeta);

}

the resulting metafile, sample.met, consists of a metafile header and six records. it has the following binary form:

0001 mttype... disk metafile

0009 mtsize...

0300 mtversion

0000 0036 mtsize

0002 mtnoobjects

0000 000c mtmaxrecord

0000 mtnoparameters

0000 0008 rdsize

02fa rdfunction (createpenindirect function)

0000 0000 0000 0000 ff00 rdparm (logpen structure defining pen)

0000 0004 rdsize

012d rdfunction (selectobject)

0000 rdparm (index to object #0... the above pen)

0000 0007 rdsize

02fc rdfunction (createbrushindirect)

0000 00ff 00ff 0000 rdparm (logbrush structure defining the brush)

0000 0004 rdsize

012d rdfunction (selectobject)

0001 rdparm (index to object #1... the brush)

0000 0007 rdsize

041b rdfunction (rectangle)

0046 0096 0000 0000 rdparm (parameters sent to rectangle...

in reverse order)

0000 000c rdsize

0521 rdfunction (textout)

rdparm

000c count

string

48 65 6c 6c 6f 20 50 65 6f 70 6c 65 "hello people"

000a y-value

000a x-value

那么如何生成wmf图呢?

MATHTYPE/LATEX/WMF解析.pdf MATHTYPE是一款专业的数学公式编辑器,兼容OFFICE WORD,EXCEL等700多

种程序,用于编辑数学试卷、书籍、报刊、论文、幻灯演示等文档轻松输

入各种复杂的数学公式和符号;

LATEX是一种基于ΤΕΧ的排版系统。对于生成复杂表格和数学公式,表现得尤为突出

WMF格式是一种图元文件。图元文件的扩展名包括.WMF和.EMF两种。它们

是属于矢量类图形,是由简单的线条和封闭线条(图形)组成的矢量图,

其主要特点是文件非常小,可以任意缩放而不影响图像质量。

SVG 是使用 XML 来描述二维图形和绘图程序的语言。

....... 将WMF图片格式转换成PNG 使用batik工具库将wmf格式的图片先转换成svg再将svg转换为png,项目下载导入即可运行 wmf 转png/jpg 将wmf格式的图片先转换成svg再将svg转换为png,项目下载导入即可运行 wmf:纯Java库可生成Windows WMF文件 wmf

纯Java库可生成Windows WMF文件

参见

这是尝试从纯Java代码生成Windows WMF文件的尝试。 文件已使用在上生成

该文件尚未编译,因此欢迎您提供任何帮助。

一旦我们可以正常工作,它将被集成到主要的PlantUML库中。

缺少的东西:

BinaryReader / BinaryWriter

待办事项:Java中没有预处理器 bettewmf cad输出wmf工具 bettewmf,是一个支持vlisp编程,同时也是cad的一款输出wmf格式的工具,输出的wmf是经过处理的。大小正好。同时由参数可以调整。

压缩文件中包含破解码。

C#

111,104

社区成员

642,560

社区内容

发帖 与我相关 我的任务 C# .NET技术 C# 复制链接

扫一扫 分享 确定 社区描述 .NET技术 C# 社区管理员

加入社区

获取链接或二维码

近7日

近30日

至今

加载中

查看更多榜单

社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧

+ 用AI写文章


吐血整理100+!南京最全zan鸭子地图!看完我出门zan鸭子去了!
手游传奇挂机软件推荐?哪个好用?