Embedded images with transparent background
#1
Hi,

I work with a wmf-file with embedded png-files. They have transparent backgrounds.
Unfortunately I couldn't find out how to detect the transparent color. After saving I always lost the transparancy.

I also tried with Paste2Xaml, same behaviour.
Any ideas?

Thanks
Michael
#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
#3
Thank you for the sample files.

I have checked them and also tried to export from PowerPoint 2007 to wmf and emf.

As you have already discovered, PowerPoint is not correctly exporting the images. The page background is blended into the image on the parts where the image should be transparent.

As a whole the metafile is correctly imported and shown, but some individual images are not correct.

However, I have found a workaround.

First open Paste2Xaml and convert the whole metafile (wmf or emf) into xaml and export it with embedded images.

Now go to Power Point and select only the image that is not correctly exported from Power Point. Copy the image to clipboard.

Now go to Paste2Xaml and click paste button (the third button on bottom left). Now the image will be correctly exported into Paste2Xaml - now you can save the xaml with image. The transparencies on the image will be correct now. :cool:

I hope this solution will be ok for you.
#4
Thanks for your help.

I figured out another workaround:
I used emf instead of wmf. In that case the background of the embedded file is still not transparent, but merged the background-file into its transparent aera.
So it seems to be transparent (it's ok as long I do not move the file to another position)

Michael
  


Forum Jump:


Users browsing this thread:
1 Guest(s)