コード例 #1
0
        private IntPtr RenderWindowsMetafilePict(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderWindowsMetafilePict");

            if (!(tymed == TYMED.TYMED_MFPICT))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_MFPICT");
            }

            if (null != _graphDocumentBitmapImage)
            {
                using (var rgbBitmap = GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel))
                {
                    var scaledDocSize = _graphDocumentSize * _graphExportOptions.OutputScalingFactor;

                    using (var enhancedMetafile = GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(rgbBitmap, scaledDocSize))
                    {
                        var hEmf = enhancedMetafile.GetHenhmetafile();
                        return(DataObjectHelper.ConvertEnhancedMetafileToWindowsMetafilePict(hEmf, scaledDocSize.X, scaledDocSize.Y));
                    }
                }
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
コード例 #2
0
        /// <summary>
        /// Determines whether the data object is capable of rendering the data described
        /// in the passed clipboard format and storage type(s). Objects attempting a
        /// paste or drop operation can call this method before calling GetData
        /// to get an indication of whether the operation may be successful
        /// </summary>
        /// <param name="clipFormat">Name of clipboard format requested</param>
        /// <param name="types">type(s) requested</param>
        /// <returns>true if the subseqent call to GetData would likely be
        /// successful, otherwise false</returns>
        public bool QueryGetData(string clipFormat, TYMED types)
        {
            // populate contents of FORMATETC structure
            FORMATETC formatEtc = new FORMATETC();

            OleDataObjectHelper.PopulateFORMATETC(clipFormat, types, ref formatEtc);

            // try to successfully query for the data
            int result = m_dataObject.QueryGetData(ref formatEtc);

            // data is available
            if (result == HRESULT.S_OK)
            {
                return(true);
            }

            // data is not available
            else if (result == DV_E.FORMATETC)
            {
                return(false);
            }

            // unexpected error
            else
            {
                Marshal.ThrowExceptionForHR(result);
                return(false); // keep compiler happy
            }
        }
コード例 #3
0
        private void SetData(byte[] data, string formatName, TYMED tymed)
        {
            IntPtr ptrToHandle = Marshal.AllocHGlobal(data.Length);

            try
            {
                Marshal.Copy(data, 0, ptrToHandle, data.Length);

                FORMATETC format = new FORMATETC
                {
                    cfFormat = (short)DataFormats.GetFormat(formatName).Id,
                    dwAspect = DVASPECT.DVASPECT_CONTENT,
                    lindex   = -1,
                    ptd      = (IntPtr)0,
                    tymed    = tymed
                };

                STGMEDIUM medium = new STGMEDIUM
                {
                    unionmember    = ptrToHandle,
                    tymed          = TYMED.TYMED_HGLOBAL,
                    pUnkForRelease = 0
                };

                dataObject.SetData(ref format, ref medium, false);
            }
            finally
            {
                Marshal.FreeHGlobal(ptrToHandle);
            }
        }
コード例 #4
0
        private byte[] GetData(string formatName, TYMED tymed)
        {
            FORMATETC format = new FORMATETC
            {
                cfFormat = (short)DataFormats.GetFormat(formatName).Id,
                dwAspect = DVASPECT.DVASPECT_CONTENT,
                lindex   = -1,
                ptd      = (IntPtr)0,
                tymed    = tymed
            };

            STGMEDIUM medium = new STGMEDIUM
            {
                tymed          = TYMED.TYMED_NULL,
                pUnkForRelease = 0
            };

            dataObject.GetData(ref format, out medium);

            HandleRef handleRef = new HandleRef(null, medium.unionmember);

            try
            {
                IntPtr ptrToHandle = GlobalLock(handleRef);
                int    length      = GlobalSize(handleRef);
                byte[] data        = new byte[length];
                Marshal.Copy(ptrToHandle, data, 0, length);
                return(data);
            }
            finally
            {
                GlobalUnlock(handleRef);
            }
        }
コード例 #5
0
 /// <summary>
 /// Fills a FORMATETC structure.
 /// </summary>
 /// <param name="format">The format name.</param>
 /// <param name="tymed">The accepted TYMED.</param>
 /// <param name="formatETC">The structure to fill.</param>
 private static void FillFormatETC(string format, TYMED tymed, out FORMATETC formatETC)
 {
     formatETC.cfFormat = (short)RegisterClipboardFormat(format);
     formatETC.dwAspect = DVASPECT.DVASPECT_CONTENT;
     formatETC.lindex   = -1;
     formatETC.ptd      = IntPtr.Zero;
     formatETC.tymed    = tymed;
 }
コード例 #6
0
        public static IntPtr RenderLinkedObjectDescriptor(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderLinkedObjectDescriptor");

            // Brockschmidt, Inside Ole 2nd ed. page 991
            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }
            // Fill in the basic information.
            var od = new OBJECTDESCRIPTOR
            {
                // According to the documentation this is used just to find an icon.
                clsid        = typeof(GraphDocumentLinkedComObject).GUID,
                dwDrawAspect = DVASPECT.DVASPECT_CONTENT,
                sizelcx      = 0, // zero in imitation of Word/Excel, but could be box.Extent.cx;
                sizelcy      = 0, // zero in imitation of Word/Excel, but could be box.Extent.cy;
                pointlx      = 0,
                pointly      = 0
            };

            od.dwStatus = MiscStatus((int)od.dwDrawAspect);

            // Descriptive strings to tack on after the struct.
            string name        = GraphDocumentLinkedComObject.USER_TYPE;
            int    name_size   = (name.Length + 1) * sizeof(char);
            string source      = "Altaxo";
            int    source_size = (source.Length + 1) * sizeof(char);
            int    od_size     = Marshal.SizeOf(typeof(OBJECTDESCRIPTOR));

            od.dwFullUserTypeName = od_size;
            od.dwSrcOfCopy        = od_size + name_size;
            int full_size = od_size + name_size + source_size;

            od.cbSize = full_size;

            // To avoid 'unsafe', we will arrange the strings in a byte array.
            byte[]   strings = new byte[full_size];
            Encoding unicode = Encoding.Unicode;

            Array.Copy(unicode.GetBytes(name), 0, strings, od.dwFullUserTypeName, name.Length * sizeof(char));
            Array.Copy(unicode.GetBytes(source), 0, strings, od.dwSrcOfCopy, source.Length * sizeof(char));

            // Combine the strings and the struct into a single block of mem.
            IntPtr hod = Kernel32Func.GlobalAlloc(GlobalAllocFlags.GHND, full_size);

            if (!(hod != IntPtr.Zero))
            {
                throw new InvalidOperationException("GlobalAlloc operation was not successful");
            }
            IntPtr buf = Kernel32Func.GlobalLock(hod);

            Marshal.Copy(strings, 0, buf, full_size);
            Marshal.StructureToPtr(od, buf, false);

            Kernel32Func.GlobalUnlock(hod);
            return(hod);
        }
コード例 #7
0
 static FORMATETC CreateFormatEtc(string format, TYMED tymed) =>
 new FORMATETC
 {
     cfFormat = (short)DataFormats.GetDataFormat(format).Id,
     tymed    = tymed,
     dwAspect = DVASPECT.DVASPECT_CONTENT,
     lindex   = -1,
     ptd      = IntPtr.Zero
 };
コード例 #8
0
 /// <summary>
 /// Helper function to populate the contents of a FORMATETC structure
 /// using the passed clipboard format and type(s).
 /// </summary>
 /// <param name="lindex">Index of item to retreive</param>
 /// <param name="clipFormat">Name of clipboard format requested</param>
 /// <param name="types">type(s) requested</param>
 /// <param name="formatEtc">FORMATETC structure to be populated</param>
 public static void PopulateFORMATETC(
     int lindex, string clipFormat, TYMED types, ref FORMATETC formatEtc)
 {
     // populate contents of FORMATETC structure
     formatEtc.cfFormat = (ushort)User32.RegisterClipboardFormat(clipFormat);
     formatEtc.ptd      = IntPtr.Zero;
     formatEtc.dwAspect = DVASPECT.CONTENT;
     formatEtc.lindex   = lindex;
     formatEtc.tymed    = types;
 }
コード例 #9
0
        private IntPtr RenderAsDIBBitmap(TYMED tymed)
        {
            ComDebug.ReportInfo("{0}.RenderAsDIBBitmap", GetType().Name);
            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            return(EmbeddedGraphDocumentRenderingHelper.RenderAsDIBBitmap_TYMED_HGLOBAL(tymed, _document));
        }
コード例 #10
0
 /// <summary>
 /// Helper function to populate the contents of a FORMATETC structure
 /// using the passed clipboard format and type(s).
 /// </summary>
 /// <param name="lindex">Index of item to retreive</param>
 /// <param name="clipFormat">Name of clipboard format requested</param>
 /// <param name="types">type(s) requested</param>
 /// <param name="formatEtc">FORMATETC structure to be populated</param>
 public static void PopulateFORMATETC(
     int lindex, string clipFormat, TYMED types, ref FORMATETC formatEtc)
 {
     // populate contents of FORMATETC structure
     formatEtc.cfFormat = (ushort)User32.RegisterClipboardFormat(clipFormat);
     formatEtc.ptd = IntPtr.Zero;
     formatEtc.dwAspect = DVASPECT.CONTENT;
     formatEtc.lindex = lindex;
     formatEtc.tymed = types;
 }
コード例 #11
0
ファイル: DataObject.cs プロジェクト: Jessie-Zhang01/origin
 private bool GetTymedUseable(TYMED tymed)
 {
     for (int i = 0; i < ALLOWED_TYMEDS.Length; i++)
     {
         if ((tymed & ALLOWED_TYMEDS[i]) != 0)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #12
0
        private IntPtr RenderEnhancedMetafile(TYMED tymed)
        {
            ComDebug.ReportInfo("{0}.RenderEnhancedMetafile", GetType().Name);

            if (!(tymed == TYMED.TYMED_ENHMF))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");
            }

            return(EmbeddedGraphDocumentRenderingHelper.RenderEnhancedMetafile_TYMED_ENHMF(tymed, _document));
        }
コード例 #13
0
        private IntPtr RenderWindowsMetafilePict(TYMED tymed)
        {
            ComDebug.ReportInfo("{0}.RenderWindowsMetafilePict", GetType().Name);

            if (!(tymed == TYMED.TYMED_MFPICT))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_MFPICT");
            }

            return(EmbeddedGraphDocumentRenderingHelper.RenderWindowsMetafilePict_TYMED_MFPICT(tymed, _document));
        }
コード例 #14
0
        private IntPtr RenderMoniker(TYMED tymed)
        {
            ComDebug.ReportInfo("{0}.RenderMoniker", GetType().Name);

            if (!(tymed == TYMED.TYMED_ISTREAM))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_ISTREAM");
            }

            return(DataObjectHelper.RenderMonikerToNewStream(tymed, CreateNewDocumentMoniker()));
        }
コード例 #15
0
 private static Boolean GetTymedUseable(TYMED tymed)
 {
     for (Int32 i = 0; i < ALLOWED_TYMEDS.Length; i++)
     {
         if ((tymed & ALLOWED_TYMEDS[i]) != TYMED.TYMED_NULL)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #16
0
ファイル: EnumFormatEtc.cs プロジェクト: olesar/Altaxo
 public Rendering(short format, TYMED tymed, RenderDataProcedure renderer)
 {
     this.format = new FORMATETC()
     {
         cfFormat = format,
         ptd      = IntPtr.Zero,
         dwAspect = DVASPECT.DVASPECT_CONTENT,
         lindex   = -1, // all
         tymed    = tymed
     };
     this.renderer = renderer;
 }
コード例 #17
0
ファイル: RemoteDataObject.cs プロジェクト: MikeMatt16/Abide
 private bool GetTymedUsable(TYMED tymed)
 {
     //Loop through allowed tymeds
     for (int i = 0; i < ALLOWED_TYMEDS.Length; i++)
     {
         if (tymed.HasFlag(ALLOWED_TYMEDS[i]))
         {
             return(true);    //If tymed is allowed just return true
         }
     }
     //Return
     return(false);
 }
コード例 #18
0
        /// <summary>
        /// Sets managed data to a clipboard DataObject.
        /// </summary>
        /// <param name="dataObject">The DataObject to set the data on.</param>
        /// <param name="format">The clipboard format.</param>
        /// <param name="data">The data object.</param>
        /// <remarks>
        /// Because the underlying data store is not storing managed objects, but
        /// unmanaged ones, this function provides intelligent conversion, allowing
        /// you to set unmanaged data into the COM implemented IDataObject.</remarks>
        public static void SetDataEx(this IDataObject dataObject, string format, object data)
        {
            DataFormat dataFormat = DataFormats.GetDataFormat(format);

            // Initialize the format structure
            var formatETC = new FORMATETC();

            formatETC.cfFormat = (short)dataFormat.Id;
            formatETC.dwAspect = DVASPECT.DVASPECT_CONTENT;
            formatETC.lindex   = -1;
            formatETC.ptd      = IntPtr.Zero;

            // Try to discover the TYMED from the format and data
            TYMED tymed = GetCompatibleTymed(format, data);

            // If a TYMED was found, we can use the system DataObject
            // to convert our value for us.
            if (tymed != TYMED.TYMED_NULL)
            {
                formatETC.tymed = tymed;

                // Set data on an empty DataObject instance
                var conv = new System.Windows.DataObject();
                conv.SetData(format, data, true);

                // Now retrieve the data, using the COM interface.
                // This will perform a managed to unmanaged conversion for us.
                STGMEDIUM medium;
                ((ComIDataObject)conv).GetData(ref formatETC, out medium);
                try
                {
                    // Now set the data on our data object
                    ((ComIDataObject)dataObject).SetData(ref formatETC, ref medium, true);
                }
                catch
                {
                    // On exceptions, release the medium
                    ReleaseStgMedium(ref medium);
                    throw;
                }
            }
            else
            {
                // Since we couldn't determine a TYMED, this data
                // is likely custom managed data, and won't be used
                // by unmanaged code, so we'll use our custom marshaling
                // implemented by our COM IDataObject extensions.

                ComDataObjectExtensions.SetManagedData((ComIDataObject)dataObject, format, data);
            }
        }
コード例 #19
0
        /// <summary>
        /// Renders the provided graph document to an device independent bitmap (TYMED_HGLOBAL). Please not that this format does not support transparancy, thus the back color provided in the rendering options is used as ground brush first.
        /// </summary>
        /// <param name="tymed">The tymed to check.</param>
        /// <param name="document">The graph document.</param>
        /// <returns>Pointer to the device independent bitmap (TYMED_HGLOBAL).</returns>
        public static IntPtr RenderAsDIBBitmap_TYMED_HGLOBAL(TYMED tymed, GraphDocumentBase document)
        {
            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            var renderingOptions = GetRenderingOptions(document);

            using (var bmp = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsBitmap(document, renderingOptions, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
            {
                return(DataObjectHelper.RenderDIBBitmapToHGLOBAL(bmp));
            }
        }
コード例 #20
0
ファイル: DataObjectHelper.cs プロジェクト: olesar/Altaxo
        /// <summary>
        /// Creates a new stream and renders the moniker into this stream. This function is intended for use with GetData(), but (!) not with GetDataHere().
        /// </summary>
        /// <param name="tymed">The tymed.</param>
        /// <param name="moniker">The moniker to render into the stream.</param>
        /// <returns>Newly created stream with the moniker rendered into.</returns>
        public static IntPtr RenderMonikerToNewStream(TYMED tymed, IMoniker moniker)
        {
            if (!(tymed == TYMED.TYMED_ISTREAM))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_ISTREAM");
            }

            int hr = Ole32Func.CreateStreamOnHGlobal(IntPtr.Zero, true, out var strm);

            if (!(hr == ComReturnValue.S_OK))
            {
                throw new InvalidOperationException("The COM operation was not successful");
            }
            SaveMonikerToStream(moniker, strm);
            return(Marshal.GetIUnknownForObject(strm)); // Increments the reference count
        }
コード例 #21
0
ファイル: DataObjectHelper.cs プロジェクト: olesar/Altaxo
        /// <summary>
        /// Creates a new IStream as global data and renders data into it.
        /// </summary>
        /// <param name="tymed">The tymed. Used only to make sure we have the right tymed.</param>
        /// <param name="RenderToStreamProcedure">The render to stream procedure.</param>
        /// <returns>Global pointer to that stream.</returns>
        public static IntPtr RenderToNewStream(TYMED tymed, Action <IStream> RenderToStreamProcedure)
        {
            if (!(tymed == TYMED.TYMED_ISTREAM))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_ISTREAM");
            }

            int hr = Ole32Func.CreateStreamOnHGlobal(IntPtr.Zero, true, out var strm);

            if (!(hr == ComReturnValue.S_OK))
            {
                throw new InvalidOperationException();
            }

            RenderToStreamProcedure(strm);
            return(Marshal.GetIUnknownForObject(strm)); // Increments the reference count
        }
コード例 #22
0
        private IntPtr RenderBitmapAsDropFile(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.BitmapAsDropFile");

            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            EnsureDropFileCreated();

            if (!string.IsNullOrEmpty(_graphDocumentDropdownFileName))
            {
                return(DataObjectHelper.RenderFiles(new string[] { _graphDocumentDropdownFileName }));
            }
            return(IntPtr.Zero);
        }
コード例 #23
0
        private IntPtr RenderBitmapDIBV5(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderBitmapDIBV5");

            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            if (null != _graphDocumentBitmapImage)
            {
                return(DataObjectHelper.RenderDIBV5BitmapToHGLOBAL(_graphDocumentBitmapImage));
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
コード例 #24
0
ファイル: DataObjectHelper.cs プロジェクト: olesar/Altaxo
        public static IntPtr RenderToNewStream(TYMED tymed, Action <System.IO.Stream> RenderToStreamProcedure)
        {
            if (!(tymed == TYMED.TYMED_ISTREAM))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_ISTREAM");
            }

            int hr = Ole32Func.CreateStreamOnHGlobal(IntPtr.Zero, true, out var strm);

            if (!(hr == ComReturnValue.S_OK))
            {
                throw new InvalidOperationException("The COM operation was not successful");
            }
            using (var strmWrapper = new ComStreamWrapper(strm, true))
            {
                RenderToStreamProcedure(strmWrapper);
            }
            return(Marshal.GetIUnknownForObject(strm)); // Increments the reference count
        }
コード例 #25
0
        public static void SetDataEx(this IDataObject dataObject, string format, object data)
        {
            System.Windows.Forms.DataFormats.Format dataFormat = System.Windows.Forms.DataFormats.GetFormat(format);

            // Initialize the format structure
            FORMATETC formatETC = new FORMATETC();

            formatETC.cfFormat = (short)dataFormat.Id;
            formatETC.dwAspect = DVASPECT.DVASPECT_CONTENT;
            formatETC.lindex   = -1;
            formatETC.ptd      = IntPtr.Zero;

            // Try to discover the TYMED from the format and data
            TYMED tymed = GetCompatibleTymed(format, data);

            // If a TYMED was found, we can use the system DataObject
            // to convert our value for us.
            if (tymed != TYMED.TYMED_NULL)
            {
                formatETC.tymed = tymed;

                // Use a temporary standard data object to convert from managed to native.
                System.Windows.Forms.DataObject conv = new System.Windows.Forms.DataObject();
                conv.SetData(format, true, data);

                STGMEDIUM medium;
                ((IDataObject)conv).GetData(ref formatETC, out medium);
                try
                {
                    ((IDataObject)dataObject).SetData(ref formatETC, ref medium, true);
                }
                catch
                {
                    Win32.ReleaseStgMedium(ref medium);
                    throw;
                }
            }
            else
            {
                SetManagedData((IDataObject)dataObject, format, data);
            }
        }
コード例 #26
0
        /// <summary>
        /// Renders the provided graph document to an windows metafile picture (TYMED_MFPICT). Please not that this format does not support transparancy, thus the back color provided in the rendering options is used as ground brush first.
        /// </summary>
        /// <param name="tymed">The tymed to check.</param>
        /// <param name="document">The graph document.</param>
        /// <returns>Pointer to windows metafile picture (TYMED_MFPICT).</returns>
        public static IntPtr RenderWindowsMetafilePict_TYMED_MFPICT(TYMED tymed, GraphDocumentBase document)
        {
            if (!(tymed == TYMED.TYMED_MFPICT))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_MFPICT");
            }

            var renderingOptions = GetRenderingOptions(document);

            using (var rgbBitmap = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsBitmap(document, renderingOptions, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
            {
                var scaledDocSize = document.Size * renderingOptions.OutputScalingFactor;

                using (var enhancedMetafile = GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(rgbBitmap, scaledDocSize))
                {
                    var hEmf = enhancedMetafile.GetHenhmetafile();
                    return(DataObjectHelper.ConvertEnhancedMetafileToWindowsMetafilePict(hEmf, scaledDocSize.X, scaledDocSize.Y));
                }
            }
        }
コード例 #27
0
		/// <summary>
		/// Renders the provided graph document to an enhanced metafile (TYMED_ENHMF).
		/// </summary>
		/// <param name="tymed">The tymed to check.</param>
		/// <param name="document">The graph document.</param>
		/// <returns>Pointer to the enhanced metafile (TYMED_ENHMF).</returns>
		public static IntPtr RenderEnhancedMetafile_TYMED_ENHMF(TYMED tymed, GraphDocumentBase document)
		{
			if (!(tymed == TYMED.TYMED_ENHMF))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");

			var renderingOptions = GetRenderingOptions(document);
			if (renderingOptions.RenderEnhancedMetafileAsVectorFormat)
			{
				var metafile = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsEnhancedMetafileVectorFormat(document, renderingOptions);
				return metafile.GetHenhmetafile();
			}
			else
			{
				using (var bmp = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsBitmap(document, renderingOptions, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
				{
					var scaledDocSize = document.Size * renderingOptions.OutputScalingFactor;
					return GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(bmp, scaledDocSize).GetHenhmetafile();
				}
			}
		}
コード例 #28
0
        private IntPtr RenderBitmapDIB(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderBitmapDIB");

            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            if (null != _graphDocumentBitmapImage)
            {
                using (var convertedBitmap = GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel))
                {
                    return(DataObjectHelper.RenderDIBBitmapToHGLOBAL(convertedBitmap));
                }
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
コード例 #29
0
        /// <summary>
        /// Renders the provided graph document to an enhanced metafile (TYMED_ENHMF).
        /// </summary>
        /// <param name="tymed">The tymed to check.</param>
        /// <param name="document">The graph document.</param>
        /// <returns>Pointer to the enhanced metafile (TYMED_ENHMF).</returns>
        public static IntPtr RenderEnhancedMetafile_TYMED_ENHMF(TYMED tymed, GraphDocumentBase document)
        {
            if (!(tymed == TYMED.TYMED_ENHMF))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");
            }

            var renderingOptions = GetRenderingOptions(document);

            if (renderingOptions.RenderEnhancedMetafileAsVectorFormat)
            {
                var metafile = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsEnhancedMetafileVectorFormat(document, renderingOptions);
                return(metafile.GetHenhmetafile());
            }
            else
            {
                using (var bmp = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsBitmap(document, renderingOptions, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    var scaledDocSize = document.Size * renderingOptions.OutputScalingFactor;
                    return(GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(bmp, scaledDocSize).GetHenhmetafile());
                }
            }
        }
コード例 #30
0
        private IntPtr RenderEnhancedMetaFile(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderEnhancedMetafile");

            if (!(tymed == TYMED.TYMED_ENHMF))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");
            }

            if (null != _graphDocumentMetafileImage)
            {
                var mfCloned = (System.Drawing.Imaging.Metafile)_graphDocumentMetafileImage.Clone();
                return(mfCloned.GetHenhmetafile());
            }
            else if (null != _graphDocumentBitmapImage)
            {
                var scaledDocSize = _graphDocumentSize * _graphExportOptions.OutputScalingFactor;
                return(GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(_graphDocumentBitmapImage, scaledDocSize).GetHenhmetafile());
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
コード例 #31
0
		private IntPtr RenderEmbeddedObjectDescriptor(TYMED tymed)
		{
			ComDebug.ReportInfo("{0}.RenderEmbeddedObjectDescriptor", this.GetType().Name);
			return GraphDocumentDataObject.RenderEmbeddedObjectDescriptor(tymed, _document.Size);
		}
コード例 #32
0
        /// <summary>
        /// Determines whether the data object is capable of rendering the data described
        /// in the passed clipboard format and storage type(s). Objects attempting a
        /// paste or drop operation can call this method before calling GetData
        /// to get an indication of whether the operation may be successful
        /// </summary>
        /// <param name="clipFormat">Name of clipboard format requested</param>
        /// <param name="types">type(s) requested</param>
        /// <returns>true if the subseqent call to GetData would likely be
        /// successful, otherwise false</returns>
        public bool QueryGetData(string clipFormat, TYMED types)
        {
            // populate contents of FORMATETC structure
            FORMATETC formatEtc = new FORMATETC();
            OleDataObjectHelper.PopulateFORMATETC(clipFormat, types, ref formatEtc);

            // try to successfully query for the data
            int result = m_dataObject.QueryGetData(ref formatEtc);

            // data is available
            if (result == HRESULT.S_OK)
                return true;

            // data is not available
            else if (result == DV_E.FORMATETC)
                return false;

            // unexpected error
            else
            {
                Marshal.ThrowExceptionForHR(result);
                return false; // keep compiler happy
            }
        }
コード例 #33
0
 public IntPtr RenderLink(TYMED tymed)
 {
     return(DataObjectHelper.RenderMonikerToNewStream(tymed, Moniker));
 }
コード例 #34
0
		private IntPtr RenderAsDIBBitmap(TYMED tymed)
		{
			ComDebug.ReportInfo("{0}.RenderAsDIBBitmap", this.GetType().Name);
			if (!(tymed == TYMED.TYMED_HGLOBAL))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");

			return EmbeddedGraphDocumentRenderingHelper.RenderAsDIBBitmap_TYMED_HGLOBAL(tymed, _document);
		}
コード例 #35
0
		private IntPtr RenderEnhancedMetaFile(TYMED tymed)
		{
			ComDebug.ReportInfo("GraphDocumentDataObject.RenderEnhancedMetafile");

			if (!(tymed == TYMED.TYMED_ENHMF))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");

			if (null != _graphDocumentMetafileImage)
			{
				var mfCloned = (System.Drawing.Imaging.Metafile)_graphDocumentMetafileImage.Clone();
				return mfCloned.GetHenhmetafile();
			}
			else if (null != _graphDocumentBitmapImage)
			{
				var scaledDocSize = _graphDocumentSize * _graphExportOptions.OutputScalingFactor;
				return GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(_graphDocumentBitmapImage, scaledDocSize).GetHenhmetafile();
			}
			else
			{
				throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
			}
		}
コード例 #36
0
		private IntPtr RenderBitmapDIB(TYMED tymed)
		{
			ComDebug.ReportInfo("GraphDocumentDataObject.RenderBitmapDIB");

			if (!(tymed == TYMED.TYMED_HGLOBAL))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");

			if (null != _graphDocumentBitmapImage)
			{
				using (var convertedBitmap = GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel))
				{
					return DataObjectHelper.RenderDIBBitmapToHGLOBAL(convertedBitmap);
				}
			}
			else
			{
				throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
			}
		}
コード例 #37
0
		private IntPtr RenderWindowsMetafilePict(TYMED tymed)
		{
			ComDebug.ReportInfo("{0}.RenderWindowsMetafilePict", this.GetType().Name);

			if (!(tymed == TYMED.TYMED_MFPICT))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_MFPICT");

			return EmbeddedGraphDocumentRenderingHelper.RenderWindowsMetafilePict_TYMED_MFPICT(tymed, _document);
		}
コード例 #38
0
ファイル: DataObjectExtensions.cs プロジェクト: kingpin2k/MCS
 private static void FillFormatETC(string format, TYMED tymed, out FORMATETC formatETC)
 {
     formatETC.cfFormat = (short)Advent.Common.Interop.NativeMethods.RegisterClipboardFormat(format);
     formatETC.dwAspect = DVASPECT.DVASPECT_CONTENT;
     formatETC.lindex = -1;
     formatETC.ptd = IntPtr.Zero;
     formatETC.tymed = tymed;
 }
コード例 #39
0
            /// <summary>
            ///  Retrieves the specified format data from the bound IComDataObject, from
            ///  other sources that IStream and HGLOBAL... this is really just a place
            ///  to put the "special" formats like BITMAP, ENHMF, etc.
            /// </summary>
            private object?GetDataFromOleOther(string format)
            {
                Debug.Assert(_innerData is not null, "You must have an innerData on all DataObjects");

                FORMATETC formatetc = new FORMATETC();
                STGMEDIUM medium    = new STGMEDIUM();

                TYMED tymed = (TYMED)0;

                if (format.Equals(DataFormats.Bitmap))
                {
                    tymed = TYMED.TYMED_GDI;
                }

                if (tymed == (TYMED)0)
                {
                    return(null);
                }

                formatetc.cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id));
                formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatetc.lindex   = -1;
                formatetc.tymed    = tymed;

                object?data = null;

                if ((int)HRESULT.S_OK == QueryGetDataUnsafe(ref formatetc))
                {
                    try
                    {
                        _innerData.GetData(ref formatetc, out medium);
                    }
                    catch
                    {
                    }
                }

                try
                {
                    if (medium.tymed == TYMED.TYMED_GDI && medium.unionmember != IntPtr.Zero)
                    {
                        if (format.Equals(DataFormats.Bitmap))
                        {
                            // ASURT 140870 -- GDI+ doesn't own this HBITMAP, but we can't
                            // delete it while the object is still around.  So we have to do the really expensive
                            // thing of cloning the image so we can release the HBITMAP.

                            // This bitmap is created by the com object which originally copied the bitmap to the
                            // clipboard. We call Add here, since DeleteObject calls Remove.
                            Image clipboardImage = Image.FromHbitmap(medium.unionmember);
                            if (clipboardImage is not null)
                            {
                                Image firstImage = clipboardImage;
                                clipboardImage = (Image)clipboardImage.Clone();
                                firstImage.Dispose();
                            }

                            data = clipboardImage;
                        }
                    }
                }
                finally
                {
                    Ole32.ReleaseStgMedium(ref medium);
                }

                return(data);
            }
コード例 #40
0
		private IntPtr RenderBitmapAsDropFile(TYMED tymed)
		{
			ComDebug.ReportInfo("GraphDocumentDataObject.BitmapAsDropFile");

			if (!(tymed == TYMED.TYMED_HGLOBAL))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");

			EnsureDropFileCreated();

			if (!string.IsNullOrEmpty(_graphDocumentDropdownFileName))
			{
				return DataObjectHelper.RenderFiles(new string[] { _graphDocumentDropdownFileName });
			}
			return IntPtr.Zero;
		}
コード例 #41
0
ファイル: OleDataObject.cs プロジェクト: pvginkel/SystemEx
 private static Boolean GetTymedUseable(TYMED tymed)
 {
     for (Int32 i = 0; i < ALLOWED_TYMEDS.Length; i++)
     {
         if ((tymed & ALLOWED_TYMEDS[i]) != TYMED.TYMED_NULL)
         {
             return true;
         }
     }
     return false;
 }
コード例 #42
0
		/// <summary>
		/// Renders the provided graph document to an device independent bitmap (TYMED_HGLOBAL). Please not that this format does not support transparancy, thus the back color provided in the rendering options is used as ground brush first.
		/// </summary>
		/// <param name="tymed">The tymed to check.</param>
		/// <param name="document">The graph document.</param>
		/// <returns>Pointer to the device independent bitmap (TYMED_HGLOBAL).</returns>
		public static IntPtr RenderAsDIBBitmap_TYMED_HGLOBAL(TYMED tymed, GraphDocumentBase document)
		{
			if (!(tymed == TYMED.TYMED_HGLOBAL))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");

			var renderingOptions = GetRenderingOptions(document);
			using (var bmp = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsBitmap(document, renderingOptions, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
			{
				return DataObjectHelper.RenderDIBBitmapToHGLOBAL(bmp);
			}
		}
コード例 #43
0
        /// <summary>
        /// Extract the date from within an OleDataObject. Pass in the requested
        /// clipboard format and type (or types ORed together) that you want
        /// the data in. The method will return an OleStgMedium for the type(s)
        /// requested if it is available, otherwise it will return null.
        /// If a single type is requested then the return value can be safely
        /// cast to the requested OleStgMedium subclasss. If multiple types
        /// are requested then the return value will represent the object's
        /// preferred storage representation and client code will need to use
        /// the 'is' operator to determine what type was returned.
        /// </summary>
        /// <param name="lindex">Index of item to retreive</param>
        /// <param name="clipFormat">Name of clipboard format requested</param>
        /// <param name="types">type(s) requested</param>
        /// <returns>OleStgMedium instance if format and requested storage type
        /// are available, otherwise null</returns>
        public OleStgMedium GetData(int lindex, string clipFormat, TYMED types)
        {
            // populate contents of FORMATETC structure
            FORMATETC formatEtc = new FORMATETC();
            OleDataObjectHelper.PopulateFORMATETC(lindex, clipFormat, types, ref formatEtc);

            // attempt to get the data using the requested format
            STGMEDIUM stgMedium = new STGMEDIUM();
            if (m_dataObject != null)
            {
                int result = m_dataObject.GetData(ref formatEtc, ref stgMedium);

                // check for errors
                if (result != HRESULT.S_OK)
                {
                    // data format not supported (expected error condition)
                    if (result == DV_E.FORMATETC)
                        return null;

                    // unexpected error condition
                    else
                        Marshal.ThrowExceptionForHR(result);
                }

                // return the correct OleStgMedium subclass depending upon the type
                switch (stgMedium.tymed)
                {
                    case TYMED.NULL:
                        return null;
                    case TYMED.HGLOBAL:
                        return new OleStgMediumHGLOBAL(stgMedium);
                    case TYMED.FILE:
                        return new OleStgMediumFILE(stgMedium);
                    case TYMED.GDI:
                        return new OleStgMediumGDI(stgMedium);
                    case TYMED.MFPICT:
                        return new OleStgMediumMFPICT(stgMedium);
                    case TYMED.ENHMF:
                        return new OleStgMediumENHMF(stgMedium);
                    case TYMED.ISTREAM:
                        return new OleStgMediumISTREAM(stgMedium);
                    case TYMED.ISTORAGE:
                        return new OleStgMediumISTORAGE(stgMedium);
                    default:
                        Debug.Assert(false, "Invalid TYMED value");
                        return null;
                }
            }
            else
                return null;
        }
コード例 #44
0
		private IntPtr RenderMoniker(TYMED tymed)
		{
			ComDebug.ReportInfo("{0}.RenderMoniker", this.GetType().Name);

			if (!(tymed == TYMED.TYMED_ISTREAM))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_ISTREAM");

			return DataObjectHelper.RenderMonikerToNewStream(tymed, CreateNewDocumentMoniker());
		}
コード例 #45
0
		public static IntPtr RenderLinkedObjectDescriptor(TYMED tymed)
		{
			ComDebug.ReportInfo("GraphDocumentDataObject.RenderLinkedObjectDescriptor");

			// Brockschmidt, Inside Ole 2nd ed. page 991
			if (!(tymed == TYMED.TYMED_HGLOBAL))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
			// Fill in the basic information.
			OBJECTDESCRIPTOR od = new OBJECTDESCRIPTOR();
			// According to the documentation this is used just to find an icon.
			od.clsid = typeof(GraphDocumentLinkedComObject).GUID;
			od.dwDrawAspect = DVASPECT.DVASPECT_CONTENT;
			od.sizelcx = 0; // zero in imitation of Word/Excel, but could be box.Extent.cx;
			od.sizelcy = 0; // zero in imitation of Word/Excel, but could be box.Extent.cy;
			od.pointlx = 0;
			od.pointly = 0;
			od.dwStatus = MiscStatus((int)od.dwDrawAspect);

			// Descriptive strings to tack on after the struct.
			string name = GraphDocumentLinkedComObject.USER_TYPE;
			int name_size = (name.Length + 1) * sizeof(char);
			string source = "Altaxo";
			int source_size = (source.Length + 1) * sizeof(char);
			int od_size = Marshal.SizeOf(typeof(OBJECTDESCRIPTOR));
			od.dwFullUserTypeName = od_size;
			od.dwSrcOfCopy = od_size + name_size;
			int full_size = od_size + name_size + source_size;
			od.cbSize = full_size;

			// To avoid 'unsafe', we will arrange the strings in a byte array.
			byte[] strings = new byte[full_size];
			Encoding unicode = Encoding.Unicode;
			Array.Copy(unicode.GetBytes(name), 0, strings, od.dwFullUserTypeName, name.Length * sizeof(char));
			Array.Copy(unicode.GetBytes(source), 0, strings, od.dwSrcOfCopy, source.Length * sizeof(char));

			// Combine the strings and the struct into a single block of mem.
			IntPtr hod = Kernel32Func.GlobalAlloc(GlobalAllocFlags.GHND, full_size);
			if (!(hod != IntPtr.Zero))
				throw new InvalidOperationException("GlobalAlloc operation was not successful");
			IntPtr buf = Kernel32Func.GlobalLock(hod);
			Marshal.Copy(strings, 0, buf, full_size);
			Marshal.StructureToPtr(od, buf, false);

			Kernel32Func.GlobalUnlock(hod);
			return hod;
		}
コード例 #46
0
		public IntPtr RenderEmbeddedObjectDescriptor(TYMED tymed)
		{
			return RenderEmbeddedObjectDescriptor(tymed, _graphDocumentSize);
		}
コード例 #47
0
 /// <summary>
 /// Helper function to populate the contents of a FORMATETC structure
 /// using the passed clipboard format and type(s).
 /// </summary>
 /// <param name="clipFormat">Name of clipboard format requested</param>
 /// <param name="types">type(s) requested</param>
 /// <param name="formatEtc">FORMATETC structure to be populated</param>
 public static void PopulateFORMATETC(
     string clipFormat, TYMED types, ref FORMATETC formatEtc)
 {
     OleDataObjectHelper.PopulateFORMATETC(-1, clipFormat, types, ref formatEtc);
 }
コード例 #48
0
		/// <summary>
		/// Renders the provided graph document to an windows metafile picture (TYMED_MFPICT). Please not that this format does not support transparancy, thus the back color provided in the rendering options is used as ground brush first.
		/// </summary>
		/// <param name="tymed">The tymed to check.</param>
		/// <param name="document">The graph document.</param>
		/// <returns>Pointer to windows metafile picture (TYMED_MFPICT).</returns>
		public static IntPtr RenderWindowsMetafilePict_TYMED_MFPICT(TYMED tymed, GraphDocumentBase document)
		{
			if (!(tymed == TYMED.TYMED_MFPICT))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_MFPICT");

			var renderingOptions = GetRenderingOptions(document);
			using (var rgbBitmap = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsBitmap(document, renderingOptions, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
			{
				var scaledDocSize = document.Size * renderingOptions.OutputScalingFactor;

				using (var enhancedMetafile = GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(rgbBitmap, scaledDocSize))
				{
					var hEmf = enhancedMetafile.GetHenhmetafile();
					return DataObjectHelper.ConvertEnhancedMetafileToWindowsMetafilePict(hEmf, scaledDocSize.X, scaledDocSize.Y);
				}
			}
		}
コード例 #49
0
ファイル: DataObject.cs プロジェクト: JianwenSun/cc
        /*
        /// <include file='doc\DataObject.uex' path='docs/doc[@for="DataObject.GetMappedFormats1"]/*' />
        /// <devdoc>
        ///     Returns all distinct "synonyms" for the each of the formats.
        /// </devdoc>
        private static string[] GetMappedFormats(string[] formats) {
            ArrayList allChoices = new ArrayList();

            for (int i=0; i<formats.Length; i++) {
                allChoices.Add(formats[i]);
            }

            if (formats != null) {
                for (int i=0; i<formats.Length; i++) {
                    string[] r = GetMappedFormats(formats[i]);
                    if (r != null) {
                        for (int j=0; j<r.Length; j++) {
                            allChoices.Add(r[j]);
                        }
                    }
                }
            }

            string[] temp = new string[allChoices.Count];
            allChoices.CopyTo(temp, 0);
            return GetDistinctStrings(temp);
        }
        */

        /// <include file='doc\DataObject.uex' path='docs/doc[@for="DataObject.GetTymedUseable"]/*' />
        /// <devdoc>
        ///     Returns true if the tymed is useable.
        /// </devdoc>
        /// <internalonly/>
        private bool GetTymedUseable(TYMED tymed) {
            for (int i=0; i<ALLOWED_TYMEDS.Length; i++) {
                if ((tymed & ALLOWED_TYMEDS[i]) != 0) {
                    return true;
                }
            }
            return false;
        }
コード例 #50
0
 /// <summary>
 /// Extract the date from within an OleDataObject. Pass in the requested
 /// clipboard format and type (or types ORed together) that you want
 /// the data in. The method will return an OleStgMedium for the type(s)
 /// requested if it is available, otherwise it will return null.
 /// If a single type is requested then the return value can be safely
 /// cast to the requested OleStgMedium subclasss. If multiple types
 /// are requested then the return value will represent the object's
 /// preferred storage representation and client code will need to use
 /// the 'is' operator to determine what type was returned.
 /// </summary>
 /// <param name="clipFormat">Name of clipboard format requested</param>
 /// <param name="types">type(s) requested</param>
 /// <returns>OleStgMedium instance if format and requested storage type
 /// are available, otherwise null</returns>
 public OleStgMedium GetData(string clipFormat, TYMED types)
 {
     return GetData(-1, clipFormat, types);
 }
コード例 #51
0
		public IntPtr RenderLink(TYMED tymed)
		{
			return DataObjectHelper.RenderMonikerToNewStream(tymed, this.Moniker);
		}
コード例 #52
0
		private IntPtr RenderEnhancedMetafile(TYMED tymed)
		{
			ComDebug.ReportInfo("{0}.RenderEnhancedMetafile", this.GetType().Name);

			if (!(tymed == TYMED.TYMED_ENHMF))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");

			return EmbeddedGraphDocumentRenderingHelper.RenderEnhancedMetafile_TYMED_ENHMF(tymed, _document);
		}
コード例 #53
0
		private IntPtr RenderBitmapDIBV5(TYMED tymed)
		{
			ComDebug.ReportInfo("GraphDocumentDataObject.RenderBitmapDIBV5");

			if (!(tymed == TYMED.TYMED_HGLOBAL))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");

			if (null != _graphDocumentBitmapImage)
			{
				return DataObjectHelper.RenderDIBV5BitmapToHGLOBAL(_graphDocumentBitmapImage);
			}
			else
			{
				throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
			}
		}
コード例 #54
0
		private IntPtr RenderWindowsMetafilePict(TYMED tymed)
		{
			ComDebug.ReportInfo("GraphDocumentDataObject.RenderWindowsMetafilePict");

			if (!(tymed == TYMED.TYMED_MFPICT))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_MFPICT");

			if (null != _graphDocumentBitmapImage)
			{
				using (var rgbBitmap = GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel))
				{
					var scaledDocSize = _graphDocumentSize * _graphExportOptions.OutputScalingFactor;

					using (var enhancedMetafile = GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(rgbBitmap, scaledDocSize))
					{
						var hEmf = enhancedMetafile.GetHenhmetafile();
						return DataObjectHelper.ConvertEnhancedMetafileToWindowsMetafilePict(hEmf, scaledDocSize.X, scaledDocSize.Y);
					}
				}
			}
			else
			{
				throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
			}
		}