void DrawImage(RectangleF rect, CGImage image, CGAffineTransform transform) { var trans = transform; // Do our translation on the image transform trans.Translate(rect.X, rect.Height - image.Height + rect.Y); // The translation is already taken care of in the transform rect.Y = 0; rect.X = 0; // Apply our transform to the context context.ConcatCTM(trans); // we are getting an error somewhere and not sure where try { context.DrawImage(rect.ToCGRect(), image); } catch (Exception exc) { Console.WriteLine(exc.Message); } // Now we revert our image transform from the context context.ConcatCTM(trans.Invert()); }
/// <summary> /// Draws the specified Image at the specified location and with the specified shape and size. /// /// The destPoints parameter specifies three points of a parallelogram. The three PointF structures /// represent the upper-left, upper-right, and lower-left corners of the parallelogram. The fourth point /// is extrapolated from the first three to form a parallelogram. /// /// The image represented by the image object is scaled and sheared to fit the shape of the parallelogram /// specified by the destPoints parameter. /// </summary> /// <param name="image">Image.</param> /// <param name="destPoints">Destination points.</param> public void DrawImage(Image image, PointF [] destPoints) { if (image == null) { throw new ArgumentNullException("image"); } if (destPoints == null) { throw new ArgumentNullException("destPoints"); } if (destPoints.Length < 3) { throw new ArgumentException("Destination points must be an array with a length of 3 or 4. " + "A length of 3 defines a parallelogram with the upper-left, upper-right, " + "and lower-left corners. A length of 4 defines a quadrilateral with the " + "fourth element of the array specifying the lower-right coordinate."); } // Windows throws a Not Implemented error if the points are more than 3 if (destPoints.Length > 3) { throw new NotImplementedException(); } if (image.nativeMetafilePage != null) { throw new NotImplementedException(); } // create our rectangle. Offset is 0 because the CreateGeometricTransform bakes our x,y offset in there. var rect = new RectangleF(0, 0, destPoints [1].X - destPoints [0].X, destPoints [2].Y - destPoints [0].Y); // We need to flip our Y axis so the image appears right side up var geoTransform = new CGAffineTransform(1, 0, 0, -1, 0, rect.Height); //var geott = GeomUtilities.CreateGeometricTransform (rect, destPoints); geoTransform.Multiply(GeomUtilities.CreateGeometricTransform(rect, destPoints)); // Apply our transform to the context context.ConcatCTM(geoTransform); // now we draw our image. context.DrawImage(rect.ToCGRect(), image.NativeCGImage); // Now we revert our image transform from the context var revert = CGAffineTransform.CGAffineTransformInvert(geoTransform); context.ConcatCTM(revert); }
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); } if (image.NativeCGImage == null) { DrawImage(image, destRect); return; } // 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 != null && (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); }
/// <summary> /// Draws the specified portion of the specified Image at the specified location and with the specified size. /// /// The destPoints specifies a parallelogram with the first point specifying the upper left corner, /// second point specifying the upper right corner and the third point specifying the lower left corner. /// /// The srcRect parameter specifies a rectangular portion of the image object to draw. This portion is scaled /// up or down (in the case where source rectangle overruns the bounds of the image) to fit inside the rectangle /// specified by the destRect parameter. /// </summary> /// <param name="image">Image.</param> /// <param name="destPoints">Destination points.</param> /// <param name="srcRect">Source rect.</param> /// <param name="srcUnit">Source unit.</param> public void DrawImage(Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit) { if (image == null) { throw new ArgumentNullException("image"); } if (destPoints == null) { throw new ArgumentNullException("destPoints"); } if (destPoints.Length < 3) { throw new ArgumentException("Destination points must be an array with a length of 3 or 4. " + "A length of 3 defines a parallelogram with the upper-left, upper-right, " + "and lower-left corners. A length of 4 defines a quadrilateral with the " + "fourth element of the array specifying the lower-right coordinate."); } // Windows throws a Not Implemented error if the points are more than 3 if (destPoints.Length > 3) { throw new NotImplementedException(); } var srcRect1 = srcRect; // 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); } if (srcRect1.Location == Point.Empty && srcRect1.Size == image.Size) { DrawImage(image, destPoints); return; } if (image.NativeCGImage == null) { throw new NotImplementedException(); } // 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; } // create our rectangle. Offset is 0 because the CreateGeometricTransform bakes our x,y offset in there. var rect = new RectangleF(0, 0, destPoints [1].X - destPoints [0].X, destPoints [2].Y - destPoints [0].Y); // We need to flip our Y axis so the image appears right side up var geoTransform = new CGAffineTransform(1, 0, 0, -1, 0, rect.Height); // Make sure we scale the image in case the source rectangle // overruns our subimage bounds (width and/or height) float scaleX = subImage.Width / srcRect1.Width; float scaleY = subImage.Height / srcRect1.Height; geoTransform.Scale(scaleX, scaleY); //var geott = GeomUtilities.CreateGeometricTransform (rect, destPoints); geoTransform.Multiply(GeomUtilities.CreateGeometricTransform(rect, destPoints)); // Apply our transform to the context context.ConcatCTM(geoTransform); // now we draw our image. context.DrawImage(rect.ToCGRect(), subImage); // Now we revert our image transform from the context var revert = CGAffineTransform.CGAffineTransformInvert(geoTransform); context.ConcatCTM(revert); subImage.Dispose(); }
void RectanglePath(RectangleF rectangle) { MoveTo (rectangle.Location); context.AddRect(rectangle.ToCGRect ()); context.ClosePath(); }
public void DrawEllipse(Pen pen, RectangleF rect) { if (pen == null) throw new ArgumentNullException ("pen"); context.AddEllipseInRect (rect.ToCGRect ()); StrokePen(pen); }
public void FillEllipse(Brush brush, RectangleF rect) { if (brush == null) throw new ArgumentNullException ("brush"); context.AddEllipseInRect(rect.ToCGRect ()); FillBrush(brush); }
private void DrawImage(RectangleF rect, CGImage image, CGAffineTransform transform) { var trans = transform; // Do our translation on the image transform trans.Translate (rect.X, rect.Height - image.Height + rect.Y); // The translation is already taken care of in the transform rect.Y = 0; rect.X = 0; // Apply our transform to the context context.ConcatCTM (trans); // we are getting an error somewhere and not sure where // I think the image bitmapBlock is being corrupted somewhere try { context.DrawImage (rect.ToCGRect (), image); } catch (Exception exc) { Console.WriteLine(exc.Message); } // Now we revert our image transform from the context var revert = CGAffineTransform.CGAffineTransformInvert (trans); context.ConcatCTM (revert); }
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); }
/// <summary> /// Draws the specified portion of the specified Image at the specified location and with the specified size. /// /// The destPoints specifies a parallelogram with the first point specifying the upper left corner, /// second point specifying the upper right corner and the third point specifying the lower left corner. /// /// The srcRect parameter specifies a rectangular portion of the image object to draw. This portion is scaled /// up or down (in the case where source rectangle overruns the bounds of the image) to fit inside the rectangle /// specified by the destRect parameter. /// </summary> /// <param name="image">Image.</param> /// <param name="destPoints">Destination points.</param> /// <param name="srcRect">Source rect.</param> /// <param name="srcUnit">Source unit.</param> public void DrawImage(Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit) { if (image == null) throw new ArgumentNullException ("image"); if (destPoints == null) throw new ArgumentNullException ("destPoints"); if (destPoints.Length < 3) throw new ArgumentException ("Destination points must be an array with a length of 3 or 4. " + "A length of 3 defines a parallelogram with the upper-left, upper-right, " + "and lower-left corners. A length of 4 defines a quadrilateral with the " + "fourth element of the array specifying the lower-right coordinate."); // Windows throws a Not Implemented error if the points are more than 3 if (destPoints.Length > 3) throw new NotImplementedException (); var srcRect1 = srcRect; // 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; // create our rectangle. Offset is 0 because the CreateGeometricTransform bakes our x,y offset in there. var rect = new RectangleF (0,0, destPoints [1].X - destPoints [0].X, destPoints [2].Y - destPoints [0].Y); // We need to flip our Y axis so the image appears right side up var geoTransform = new CGAffineTransform (1, 0, 0, -1, 0, rect.Height); // Make sure we scale the image in case the source rectangle // overruns our subimage bounds (width and/or height) float scaleX = subImage.Width/srcRect1.Width; float scaleY = subImage.Height/srcRect1.Height; geoTransform.Scale (scaleX, scaleY); //var geott = GeomUtilities.CreateGeometricTransform (rect, destPoints); geoTransform.Multiply (GeomUtilities.CreateGeometricTransform (rect, destPoints)); // Apply our transform to the context context.ConcatCTM (geoTransform); // now we draw our image. context.DrawImage(rect.ToCGRect (), subImage); // Now we revert our image transform from the context var revert = CGAffineTransform.CGAffineTransformInvert (geoTransform); context.ConcatCTM (revert); }
/// <summary> /// Draws the specified Image at the specified location and with the specified shape and size. /// /// The destPoints parameter specifies three points of a parallelogram. The three PointF structures /// represent the upper-left, upper-right, and lower-left corners of the parallelogram. The fourth point /// is extrapolated from the first three to form a parallelogram. /// /// The image represented by the image object is scaled and sheared to fit the shape of the parallelogram /// specified by the destPoints parameter. /// </summary> /// <param name="image">Image.</param> /// <param name="destPoints">Destination points.</param> public void DrawImage(Image image, PointF [] destPoints) { if (image == null) throw new ArgumentNullException ("image"); if (destPoints == null) throw new ArgumentNullException ("destPoints"); if (destPoints.Length < 3) throw new ArgumentException ("Destination points must be an array with a length of 3 or 4. " + "A length of 3 defines a parallelogram with the upper-left, upper-right, " + "and lower-left corners. A length of 4 defines a quadrilateral with the " + "fourth element of the array specifying the lower-right coordinate."); // Windows throws a Not Implemented error if the points are more than 3 if (destPoints.Length > 3) throw new NotImplementedException (); // create our rectangle. Offset is 0 because the CreateGeometricTransform bakes our x,y offset in there. var rect = new RectangleF (0,0, destPoints [1].X - destPoints [0].X, destPoints [2].Y - destPoints [0].Y); // We need to flip our Y axis so the image appears right side up var geoTransform = new CGAffineTransform (1, 0, 0, -1, 0, rect.Height); //var geott = GeomUtilities.CreateGeometricTransform (rect, destPoints); geoTransform.Multiply (GeomUtilities.CreateGeometricTransform (rect, destPoints)); // Apply our transform to the context context.ConcatCTM (geoTransform); // now we draw our image. context.DrawImage(rect.ToCGRect (), image.NativeCGImage); // Now we revert our image transform from the context var revert = CGAffineTransform.CGAffineTransformInvert (geoTransform); context.ConcatCTM (revert); }