Giter Site home page Giter Site logo

papnkukn / wmf Goto Github PK

View Code? Open in Web Editor NEW
31.0 2.0 11.0 77 KB

The library supports reading and writing WMF files. Source code is written in pure .NET from scratch following the Windows Metafile Format Specification.

License: MIT License

C# 97.36% Batchfile 2.64%

wmf's Introduction

Windows Metafile Library

Note: this project moved from https://wmf.codeplex.com/

Project Description

The library supports reading and writing WMF files. Source code is written in pure .NET from scratch following the Windows Metafile Format Specification.

Technical Information

  • Name: Window Metafile Format (WMF)
  • File extension: .wmf, .emf
  • Mime type: image/x-wmf, image/x-emf
  • Classification: vector/raster image
  • Identifier: D7 CD C6 9A (first four bytes)
  • Documentation: WMF Specification

Why WMF?

WMF is all about records - recorded sequence of actions. As opposite to other vector or raster image formats that define final image appearance, WMF contains intermediate states. Those states can be modified at specific working stage or can be "played" back to render an image. From other point of view WMF file natively contains "undo" history.

Another advantage of WMF is to support both vector and raster elements in one file. Disadvantage are lack of features (e.g. no element grouping like layers or trees), 16-bit limitations, bad extensibility due to old image format.

WMF can be replaced by EPS but since Windows has good integration with the WMF it is still useful in some cases: clipboard - transfering images with copy/paste, Clip Art images from MS Office are WMF, etc.

Notice

This library does not fully implement Windows Metafile Format Specification. Current library version (v0.3) supports only basic WMF records but the source code is well structured so the missing records can easily be implemented if needed. I am not planning to develop other WMF records as the current version fulfills my requirements for another project.

Examples

Create a simple WMF image with rectangle

var wmf = new WmfDocument();
wmf.Width = 1000;
wmf.Height = 1000;
wmf.Format.Unit = 288;
wmf.AddPolyFillMode(PolyFillMode.WINDING);
wmf.AddCreateBrushIndirect(Color.Blue, BrushStyle.BS_SOLID);
wmf.AddSelectObject(0);
wmf.AddCreatePenIndirect(Color.Black, PenStyle.PS_SOLID, 1);
wmf.AddSelectObject(1);
wmf.AddRectangle(100, 100, 800, 800);
wmf.AddDeleteObject(0);
wmf.AddDeleteObject(1);
wmf.Save(path);

Read a WMF file and display human-readable values for analysis

WmfDocument wmf = new WmfDocument();
wmf.Load(path);

string dump = wmf.Dump();
Console.WriteLine(dump);

Read records from WMF file

WmfDocument wmf = new WmfDocument();
wmf.Load(path);

foreach (var record in wmf.Records)
{
  if (record is WmfCreateBrushIndirectRecord)
  {
    var brush = record as WmfCreateBrushIndirectRecord;
    Console.WriteLine("Color: " + brush.Color);
    Console.WriteLine("Style: " + brush.Style);
    Console.WriteLine("Hatch: " + brush.Hatch);
  }
  else if (record is WmfRectangleRecord)
  {
    var rectangle = record as WmfRectangleRecord;
    //Do something with rectangle...
  }
}

wmf's People

Contributors

papnkukn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wmf's Issues

Invalid DIB size calculation

DeviceIndependentBitmap currently doesn't take into account the color palette stored in the DIB, which makes the size calculation incorrect. Currently it reads:

  • read 40-byte header
  • read (seemingly properly calculated amount of) data bytes into Data

But it should:

  • read 40-byte header
  • read (header.ColorsUsed ?? 1 << header.BitCount) * 4 bytes into Colors
  • read same amount of data into Data

Here's a compressed example of a file that reads incorrectly by the library: _bm0.zip.

record size issue

MS-WMF.pdf

Hello, i think this code has some issue. According to the wmf format specification:

  1. For the record type META_STRETCHBLT and META_DIBSTRETCHBLT, no matter the record with bitmap data or not, the data member "SrcHeight" and "SrcWidth" should exist.
    therefor, the file "WmfStretchBltRecord.cs" (line 76, 80) and "WmfDIBStretchBltRecord.cs" (line 76, 80) is wrong.
    If without bitmap data, the record length should be 28, not 24. and at line 80, need not this condition "if (!isWithoutBitmap)".
    2.For the record type META_STRETCHDIB, wmf format specification doesn't refer to "without bitmap data", so, i think line 82 in file "WmfDIBStretchBltRecord.cs" is unnecessary, this record type must be 28 bytes and some DIB data bytes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.