Exemple #1
0
        /// <summary>
        ///  Creates a WindowsGraphics object from a Graphics object.  Clipping and coordinate transforms
        ///  are preserved.
        ///
        ///  Notes:
        ///  - The passed Graphics object cannot be used until the WindowsGraphics is disposed
        ///  since it borrows the hdc from the Graphics object locking it.
        ///  - Changes to the hdc using the WindowsGraphics object are not preserved into the Graphics object;
        ///  the hdc is returned to the Graphics object intact.
        ///
        ///  Some background about how Graphics uses the internal hdc when created from an existing one
        ///  (mail from GillesK from GDI+ team):
        ///  User has an HDC with a particular state:
        ///  Graphics object gets created based on that HDC. We query the HDC for its state and apply it to the Graphics.
        ///  At this stage, we do a SaveHDC and clear everything out of it.
        ///  User calls GetHdc. We restore the HDC to the state it was in and give it to the user.
        ///  User calls ReleaseHdc, we save the current state of the HDC and clear everything
        ///  (so that the graphics state gets applied next time we use it).
        ///  Next time the user calls GetHdc we give him back the state after the second ReleaseHdc.
        ///  (But the state changes between the GetHdc and ReleaseHdc are not applied to the Graphics).
        ///  Please note that this only applies the HDC created graphics, for Bitmap derived graphics, GetHdc creates a new DIBSection and
        ///  things get a lot more complicated.
        /// </summary>
        public static WindowsGraphics FromGraphics(Graphics g)
        {
            ApplyGraphicsProperties properties = ApplyGraphicsProperties.All;

            return(WindowsGraphics.FromGraphics(g, properties));
        }