Esempio n. 1
0
        private IntPtr GetImage()
        {
            if (OleObject == null)
            {
                return(IntPtr.Zero);
            }

            IntPtr   hDC = Natives.CreateDC("DISPLAY", null, null, IntPtr.Zero);
            Metafile mf  = new Metafile(hDC, EmfType.EmfOnly);

            using (var g = Graphics.FromImage(mf))
            {
                OleObject.Draw(g);
            }
            IntPtr _hEmf       = mf.GetHenhmetafile();
            uint   _bufferSize = Natives.GdipEmfToWmfBits(_hEmf, 0, null, Natives.MM_ANISOTROPIC,
                                                          Natives.EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault);

            byte[] _buffer = new byte[_bufferSize];
            Natives.GdipEmfToWmfBits(_hEmf, _bufferSize, _buffer, Natives.MM_ANISOTROPIC,
                                     Natives.EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault);
            IntPtr hwmf = Natives.SetMetaFileBitsEx(_bufferSize, _buffer);

            var pic = Marshal.AllocHGlobal(20);

            Marshal.WriteInt32(pic, 0, 8 /*MM_ANISOTROPIC*/);
            Marshal.WriteInt32(pic, 4, 20000);
            Marshal.WriteInt32(pic, 8, 20000);
            Marshal.WriteIntPtr(pic, 12, hwmf);
            return(pic);
        }