Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, April 7, 2011 9:24:06 AM(UTC)

amurray  
amurray

Groups: Registered
Posts: 12


In my printer_EmfEvent, using the ChangeFromEmf method generates solid black pages. I know the metafile object is good, because the GDI code works. What am I doing wrong?

void printer_EmfEvent(object sender, Leadtools.Printer.EmfEventArgs e)
{
var metafile = new System.Drawing.Imaging.Metafile(e.Stream);

// the file produced by this code is a valid image.
using (var bmp = new System.Drawing.Bitmap(metafile.Width, metafile.Height))
{
bmp.SetResolution(metafile.HorizontalResolution, metafile.VerticalResolution);
using (var g = System.Drawing.Graphics.FromImage(bmp))
{
g.Clear(Color.White);
g.DrawImage(metafile, 0, 0, bmp.Width, bmp.Height);
bmp.Save(@"c:\temp\gdiplus.tif", System.Drawing.Imaging.ImageFormat.Tiff);
}
}

// the file produced by this code is a solid black image.
IntPtr hemf = metafile.GetHenhmetafile();
using (var image = Leadtools.Drawing.RasterImageConverter.ChangeFromEmf(hemf, 0, 0))
{
codecs.Save(image, @"c:\temp\lead.tif", Leadtools.RasterImageFormat.Tif, 32);
}
}
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Thursday, April 7, 2011 12:34:48 PM(UTC)

Danny H  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

The black you are seeing is the transparency of the emf stream. When sending print calls most document files will often send a transparent background to the emf. You're workaround is fine however we can load the emf directly with no issue.

This code is all it takes to do so:

RasterImage m_myImage = m_Codecs.Load( e.Stream );

When you save this image out it will have the proper background. ChangeFromEmf does not fill background data it merely takes the data in the emf directly out. Transparency is just interpreted as black.

You can refer to my sample for rerouting printers in a window service, as it is done in this manner there.

http://support.leadtools.com/SupportPortal/CS/forums/37468/ShowPost.aspx
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.050 seconds.