0

I am creating an enhanced metafile, which I am drawing a graph to. The graph highlights sections in red, using an alpha of 40 to give it some transparency. When the file is saved the alpha is abscent and what looks like Windows using a balance of white/red instead. My question is how can I set the metafile so that it will include the alpha?

Target alpha:

enter image description here

Actual:

enter image description here

Code to make Enhanced Metafile:

Dim gfx As Graphics = Form1.CreateGraphics
Dim hDcRef As IntPtr = gfx.GetHdc
Dim rc As RECT
Dim hDcEmf As IntPtr = CreateEnhMetaFile(hDcRef, "c:\new", rc, Nothing)

gfx.ReleaseHdc(hDcRef)
gfx.Dispose()

Dim g = Graphics.FromHdc(hDcEmf)
Graph.Draw(g)

Dim hEmf As IntPtr = CloseEnhMetaFile(hDcEmf)
g.Dispose()

Can provide the calls to GDI+ dll also if needed.

dave88
  • 312
  • 5
  • 14
  • Are you sure that you can release the reference device context before drawing on the metafile? Also, the `rc` structure that you're passing in is probably not valid. – Cody Gray - on strike Jul 25 '14 at 12:51
  • Yes, it doesn't matter where you put it as long as the metafile has been created first. Also, can you elaborate on why the RECT may be invalid Cody? – dave88 Jul 25 '14 at 12:59
  • 1
    Because you declare it without initializing it. If I remember correctly, VB.NET automatically zero-initializes objects, so you're passing in a RECT that has a top-left point at (0,0), a width of 0, and a height of 0. (If it doesn't zero-initialize, you're passing garbage.) Doesn't sound valid to me. I wasn't sure if you had omitted intervening code that initializes it, though. – Cody Gray - on strike Aug 12 '14 at 08:52

0 Answers0