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

DrawImage() public method

public DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs ) : void
image Image
destRect Rectangle
srcX float
srcY float
srcWidth float
srcHeight float
srcUnit GraphicsUnit
imageAttrs System.Drawing.Imaging.ImageAttributes
return void
        public void DrawImage(Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs)
        {
            if (image == null)
                throw new ArgumentNullException ("image");

            var srcRect1 = new RectangleF(srcX, srcY,srcWidth,srcHeight);

            // If the source units are not the same we need to convert them
            // The reason we check for Pixel here is that our graphics already has the Pixel's baked into the model view transform
            if (srcUnit != graphicsUnit && srcUnit != GraphicsUnit.Pixel)
            {
                ConversionHelpers.GraphicsUnitConversion (srcUnit, graphicsUnit, image.HorizontalResolution, image.VerticalResolution,  ref srcRect1);
            }

            // Obtain the subImage
            var subImage = image.NativeCGImage.WithImageInRect (srcRect1.ToCGRect ());

            // If we do not have anything to draw then we exit here
            if (subImage.Width == 0 || subImage.Height == 0)
                return;

            //			var transform = image.imageTransform;
            ////			// Reset our height on the transform to account for subImage
            //			transform.y0 = subImage.Height;
            ////
            ////			// Make sure we scale the image in case the source rectangle
            ////			// overruns our subimage bouncs width and/or height
            //			float scaleX = subImage.Width/srcRect1.Width;
            //			float scaleY = subImage.Height/srcRect1.Height;
            //			transform.Scale (scaleX, scaleY);
            bool attributesSet = imageAttrs.isColorMatrixSet || imageAttrs.isGammaSet;

            if (attributesSet) {
                InitializeImagingContext ();
                CIImage result = subImage;

                if (imageAttrs.isColorMatrixSet) {

                    var ciFilter = CIFilter.FromName ("CIColorMatrix");
                    ciFilter.SetDefaults ();

                    ciFilter.SetValueForKey (result, new NSString ("inputImage"));

                    var inputRVector = new CIVector (imageAttrs.colorMatrix.Matrix00, imageAttrs.colorMatrix.Matrix01, imageAttrs.colorMatrix.Matrix02, imageAttrs.colorMatrix.Matrix03);
                    var inputGVector = new CIVector (imageAttrs.colorMatrix.Matrix10, imageAttrs.colorMatrix.Matrix11, imageAttrs.colorMatrix.Matrix12, imageAttrs.colorMatrix.Matrix13);
                    var inputBVector = new CIVector (imageAttrs.colorMatrix.Matrix20, imageAttrs.colorMatrix.Matrix21, imageAttrs.colorMatrix.Matrix22, imageAttrs.colorMatrix.Matrix23);
                    var inputAVector = new CIVector (imageAttrs.colorMatrix.Matrix30, imageAttrs.colorMatrix.Matrix31, imageAttrs.colorMatrix.Matrix32, imageAttrs.colorMatrix.Matrix33);
                    var inputBiasVector = new CIVector (imageAttrs.colorMatrix.Matrix40, imageAttrs.colorMatrix.Matrix41, imageAttrs.colorMatrix.Matrix42, imageAttrs.colorMatrix.Matrix43);

                    ciFilter.SetValueForKey (inputRVector, new NSString ("inputRVector"));
                    ciFilter.SetValueForKey (inputGVector, new NSString ("inputGVector"));
                    ciFilter.SetValueForKey (inputBVector, new NSString ("inputBVector"));
                    ciFilter.SetValueForKey (inputAVector, new NSString ("inputAVector"));
                    ciFilter.SetValueForKey (inputBiasVector, new NSString ("inputBiasVector"));
                    result = (CIImage)ciFilter.ValueForKey (new NSString ("outputImage"));
                }

                if (imageAttrs.isGammaSet) {

                    var ciFilter = CIFilter.FromName ("CIGammaAdjust");
                    ciFilter.SetDefaults ();

                    ciFilter.SetValueForKey (result, new NSString ("inputImage"));

                    var inputPower = NSNumber.FromFloat (imageAttrs.gamma);

                    ciFilter.SetValueForKey (inputPower, new NSString ("inputPower"));
                    result = (CIImage)ciFilter.ValueForKey (new NSString ("outputImage"));
                }

                subImage = ciContext.CreateCGImage (result, result.Extent);
            }

            transform = image.imageTransform;
            transform.y0 = subImage.Height;
            float scaleX1 = subImage.Width/srcRect1.Width;
            float scaleY1 = subImage.Height/srcRect1.Height;
            transform.Scale (scaleX1, scaleY1);
            // Now draw our image
            DrawImage (destRect, subImage, transform);
        }

Same methods

Graphics::DrawImage ( Image image, Point destPoints ) : void
Graphics::DrawImage ( Image image, Point destPoints, Rectangle srcRect, GraphicsUnit srcUnit ) : void
Graphics::DrawImage ( Image image, Point destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr ) : void
Graphics::DrawImage ( Image image, Point destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback ) : void
Graphics::DrawImage ( Image image, Point destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData ) : void
Graphics::DrawImage ( Image image, PointF point ) : void
Graphics::DrawImage ( Image image, PointF destPoints, RectangleF srcRect, GraphicsUnit srcUnit ) : void
Graphics::DrawImage ( Image image, PointF destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr ) : void
Graphics::DrawImage ( Image image, PointF destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback ) : void
Graphics::DrawImage ( Image image, PointF destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData ) : void
Graphics::DrawImage ( Image image, Rectangle rect ) : void
Graphics::DrawImage ( Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit ) : void
Graphics::DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit ) : void
Graphics::DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback ) : void
Graphics::DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData ) : void
Graphics::DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit ) : void
Graphics::DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr ) : void
Graphics::DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback ) : void
Graphics::DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData ) : void
Graphics::DrawImage ( Image image, RectangleF rect ) : void
Graphics::DrawImage ( Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit ) : void
Graphics::DrawImage ( Image image, float x, float y ) : void
Graphics::DrawImage ( Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit ) : void
Graphics::DrawImage ( Image image, float x, float y, float width, float height ) : void
Graphics::DrawImage ( Image image, int x, int y ) : void
Graphics::DrawImage ( Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit ) : void
Graphics::DrawImage ( Image image, int x, int y, int width, int height ) : void
Graphics::DrawImage ( RectangleF rect, CGImage image, CGAffineTransform transform ) : void

Usage Example

Example #1
0
 public void _drawTabHeader(Graphics nGraphics, Font nFont, Rectangle nRectangle)
 {
     int width_ = nRectangle.Height - 2;
     switch (mSideTabStatus)
     {
         case SideTabStatus_.mNormal_:
             ControlPaint.DrawBorder3D(nGraphics, nRectangle, Border3DStyle.RaisedInner);
             nGraphics.DrawImage(mSideTabImage, nRectangle.X + 1, nRectangle.Y + 1, width_, width_);
             nGraphics.DrawString(mSideTabName, nFont, SystemBrushes.ControlText, new PointF(nRectangle.X + width_ + 2, nRectangle.Y + 2));
             break;
         case SideTabStatus_.mSelected_:
             ControlPaint.DrawBorder3D(nGraphics, nRectangle, Border3DStyle.Sunken);
             nGraphics.DrawImage(mSideTabImage, nRectangle.X + 1, nRectangle.Y + 1, width_, width_);
             nGraphics.DrawString(mSideTabName, nFont, SystemBrushes.ControlText, new PointF(nRectangle.X + width_ + 2, nRectangle.Y + 2));
             break;
         case SideTabStatus_.mDragged_:
             ControlPaint.DrawBorder3D(nGraphics, nRectangle, Border3DStyle.RaisedInner);
             nRectangle.X += 1;
             nRectangle.Y += 1;
             nRectangle.Width -= 2;
             nRectangle.Height -= 2;
             nGraphics.FillRectangle(SystemBrushes.ControlDarkDark, nRectangle);
             nGraphics.DrawString(mSideTabName, nFont, SystemBrushes.HighlightText, new PointF(nRectangle.X + width_ , nRectangle.Y));
             break;
     }
 }
All Usage Examples Of System.Drawing.Graphics::DrawImage