LEADTOOLS Support
Document
Document SDK Questions
black images when using ChangeFromEmf method
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Thursday, April 7, 2011 9:24:06 AM(UTC)
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);
}
}
#2
Posted
:
Thursday, April 7, 2011 12:34:48 PM(UTC)
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
LEADTOOLS Support
Document
Document SDK Questions
black images when using ChangeFromEmf method
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.