none
How to apply rotate transform for Metafile? RRS feed

  • Question

  • Hi,

    I tried to rotate the Metafile to 270 or 180 degree but it does not apply the rotate transform for Metafile. The blank image was return after applying the rotate transform to Metafile. And also I tried RotateFlip method to rotate the metafile but it throw Not Implement exception at System.Drawing.Metafile.

    Below code snippet used in my application.

                Metafile metafile;

                Bitmap bitmapImage = new Bitmap("c:/temp/metafile.wmf");

                Graphics g = Graphics.FromImage(bitmapImage);

                IntPtr hdc = g.GetHdc();

                using (MemoryStream stream = new MemoryStream())

                {

                   

     

                    metafile = new Metafile(stream, hdc, EmfType.EmfOnly);

                    g.ReleaseHdc(hdc);

                    using (Graphics graphics = Graphics.FromImage(metafile))

                    {

                        graphics.TranslateTransform(0, 0);

                             

                        graphics.RotateTransform(270);

                    }

               }

    Metafile.save("rotatedMetafile.wmf");

    Is it have any work around to do the rotate transform for metafile? Please share your idea on this. 

    Thanks,

    Parthipan


    Thursday, November 13, 2014 6:44 PM

Answers

  • Hello Parthipan,

    The RotateFlip method works for me with below usage:

    using (var stream = new FileStream("S20141114.wmf", FileMode.Open))
    
                    {
    
                        using (var image = Image.FromStream(stream))
    
                        {
    
                            stream.Close();
    
                            image.RotateFlip(RotateFlipType.Rotate270FlipXY);
    
                            image.Save("rotatedMetafile.wmf", System.Drawing.Imaging.ImageFormat.Wmf);
    
                            image.Dispose();
    
                        }
    
                    }
    

    You could try it.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 14, 2014 9:19 AM
    Moderator