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); // 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); }
private void UpdateFilterProperties() { RectangleF rect = Window.ContentView.Frame; var extent = new CIVector(rect.Left, rect.Bottom, rect.Width, rect.Height); var center = new CIVector(rect.GetMidX(),rect.GetMidY()); copyMachineTransition.Extent = extent; var xScale = rect.Width / transitionInputMaskImage.Extent.Width; var yScale = rect.Height / transitionInputMaskImage.Extent.Height; disintegrateTransform.Scale = yScale; disintegrateTransform.AspectRatio = xScale / yScale; disintegrateTransition.Mask = (CIImage) disintegrateTransform.ValueForKey((NSString) "outputImage"); flashTransition.Center = center; flashTransition.Extent = extent; modTransition.Center = center; pageCurlShadowTransition.SetValueForKey(extent, (NSString) "inputExtent"); pageCurlShadowTransition.SetValueForKey(extent, (NSString) "inputShadowExtent"); rippleTransition.Center = center; rippleTransition.Extent = extent; }