如何从GDI +图元文件对象获取原始图元文件字节?

时间:2019-07-17 05:24:10

标签: c++ winapi gdi+ gdi metafile

我知道我可以从GDI的HENHMETAFILE获取原始图元文件字节 使用GetEnhMetaFileBits函数。但是我如何从中获取原始字节 Gdiplus::Metafile是GDI +对象吗?

1 个答案:

答案 0 :(得分:1)

    public static void Save(Metafile matafile, Stream stream)
    {
        using (stream)
        {
            using (Bitmap bit = new Bitmap(1, 1))
            {
                using (Graphics gs = Graphics.FromImage(bit))
                {
                    Rectangle rt = new Rectangle(0, 0, matafile.Width, matafile.Height);
                    using (Metafile mf = new Metafile(stream, gs.GetHdc(), rt, MetafileFrameUnit.Pixel, EmfType.EmfOnly))
                    {
                        using (Graphics g = Graphics.FromImage(mf))
                        {
                            g.DrawImage(matafile, rt);
                        }
                    }
                }
            }
        }
    }