Author Topic: [C#] Get Visio.Shape as Imaging.Metafile  (Read 1759 times)

0 Members and 1 Guest are viewing this topic.

svetum

  • Newbie
  • *
  • Posts: 2
[C#] Get Visio.Shape as Imaging.Metafile
« on: July 27, 2016, 02:34:10 AM »
Hi,

I am trying to implement a fix for the little white buffer that appears when Visio shape is exported as metafile (EMF).
When you do PasteSpecial -> Export as EMF and then resize the image back to the original size there is a small white buffer that is visible when you place many copies of the same image next to each other.
For example, my image has a rectange 30x290, but when exported as EMF it gets a size of 29.xx x 289.xx although the image size is 30x290 (units does not matter).

I was previously using these EMFs in PDF (i.e. export the EMF as PDF) and fixing this problem on the PDF side - get the PDF, get bounding box and transformation matrix, iterate over all drawing elements, get their coordinates and then some math...

Now, I need to do this in C# automation and I am having a problem to get the shape as a metafile. If I get it as metafile, then I will probably be able to examine the EMF stream and figure out what I need. My Problem:

I have a shape which has Shape.ForeignType = 16 (visTypeMetafile)
How would I cast/convert this shape to Imaging.Metafile

Thanks,
Svet
« Last Edit: July 27, 2016, 02:46:07 AM by svetum »

svetum

  • Newbie
  • *
  • Posts: 2
Re: [C#] Get Visio.Shape as Imaging.Metafile
« Reply #1 on: July 27, 2016, 04:03:32 AM »
I guess, I had to do a bit more on my own before posting ...

Array ar = shape.ForeignData;
byte[] bytes = new Byte[ar.Length];
for (int i = 0; i < ar.Length; i++)
    bytes = (byte)ar.GetValue(i);
MemoryStream strm = new MemoryStream(bytes);
Metafile mf = new Metafile(strm);

Back to the fight with EMF.