System.Drawing.Graphics.DrawImageUnscaledAndClipped C# (CSharp) Method

DrawImageUnscaledAndClipped() public method

public DrawImageUnscaledAndClipped ( Image image, Rectangle rect ) : void
image Image
rect Rectangle
return void
        public void DrawImageUnscaledAndClipped(Image image, Rectangle rect)
        {
            if (image == null)
                throw new ArgumentNullException ("image");

            int width = (image.Width > rect.Width) ? rect.Width : image.Width;
            int height = (image.Height > rect.Height) ? rect.Height : image.Height;

            DrawImageUnscaled (image, rect.X, rect.Y, width, height);
        }

Usage Example

Example #1
0
        ///<summary>
        /// RenderButton
        ///</summary>
        ///<param name="g"></param>
        ///<param name="image"></param>
        ///<param name="buttonBounds"></param>
        ///<param name="clipBounds"></param>
        static public Size RenderButton(Graphics g, Image image,
            Rectangle buttonBounds, Rectangle clipBounds)
        {
            if (image != null && buttonBounds.IsEmpty == false)
            {
                Rectangle r = buttonBounds;
                r.Width++;
                r.Height++;

                if (r.Width > image.Width)
                {
                    r.X += (r.Width - image.Width)/2;
                    r.Width = image.Width;
                }

                if (r.Height > image.Height)
                {
                    r.Y += (r.Height - image.Height)/2;
                    r.Height = image.Height;
                }

                r.Intersect(clipBounds);

                g.DrawImageUnscaledAndClipped(image, r);

                return (r.Size);
            }

            return (Size.Empty);
        }
All Usage Examples Of System.Drawing.Graphics::DrawImageUnscaledAndClipped