Embedded images with transparent background
#2
Hi,

Is the wmf file correctly shown in Paste2Xaml - with the transparent image?

If not, than check if the wmf is correctly opened in Windows (maybe the transparency is lost when wmf file is created).


If Paste2Xaml correctly shows the metafile, you can get the images with using ReaderWmf. After reading the metafile, you can get the images from EmbeddedBitmapImages collection.

The following code can be used to save all embedded images to files to png files:

Code:
Ab2d.ReaderWmf myReaderWmf = new Ab2d.ReaderWmf();
    myReaderWmf.ShowDemoTextInEvaluation = false;
    myReaderWmf.Read("myTest.wmf");


    for (int i = 0; i < myReaderWmf.EmbeddedBitmapImages.Count; i++)
    {
        BitmapSource oneBitmap;
        string filePath;

        oneBitmap = myReaderWmf.EmbeddedBitmapImages[i];
        filePath = System.IO.Path.Combine(@"c:\test\", string.Format("image_{0}.png", i + 1));

        using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
        {
            PngBitmapEncoder enc = new PngBitmapEncoder();

            // NOTE:
            // If break on exception is turned on in VS,
            // the next line will throw an exception, but it is handled in .net framework (so click continue)
            // See also: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9f23dde5-f281-4175-a6a2-5f4ad14a4dfe/?lc=1033&ffpr=0
            enc.Frames.Add(BitmapFrame.Create(oneBitmap));
            enc.Save(fs);
        }
    }

If wmf file is correctly opened in windows and not in Paste2Xaml, than please send me the file as attachment on my Feedback page - http://www.wpf-graphics.com/Feedback.aspx
  


Messages In This Thread
RE: Embedded images with transparent background - by abenedik - 04-09-2010, 09:19 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)