void ResetSettings(UIBarButtonItem sender) { var filter = ciRawFilter; if (filter == null) { return; } filter.SetValueForKey(NSNumber.FromInt32(0), CIFilterInputKey.EV); ExposureSlider.SetValue(0, animated: false); filter.SetValueForKey(NSNumber.FromFloat(originalTemp), Keys.kCIInputNeutralTemperatureKey); TempSlider.SetValue(originalTemp, animated: false); filter.SetValueForKey(NSNumber.FromFloat(originalTint), Keys.kCIInputNeutralTintKey); TintSlider.SetValue(originalTint, animated: false); ImageView.SetNeedsDisplay(); }
// On load, construct the CIRawFilter public override void ViewDidLoad() { base.ViewDidLoad(); var asset = Asset; if (asset == null) { return; } // Setup options to request original image. var options = new PHImageRequestOptions { Version = PHImageRequestOptionsVersion.Original, Synchronous = true }; // Request the image data and UTI type for the image. PHImageManager.DefaultManager.RequestImageData(asset, options, (imageData, dataUTI, _, __) => { if (imageData == null || dataUTI == null) { return; } // Create a CIRawFilter from original image data. // UTI type is passed in to provide the CIRawFilter with a hint about the UTI type of the Raw file. //var rawOptions = [String (kCGImageSourceTypeIdentifierHint) : dataUTI ] var rawOptions = new NSMutableDictionary(); var imageIOLibrary = Dlfcn.dlopen("/System/Library/Frameworks/ImageIO.framework/ImageIO", 0); var key = Dlfcn.GetIntPtr(imageIOLibrary, "kCGImageSourceTypeIdentifierHint"); rawOptions.LowlevelSetObject(dataUTI, key); ciRawFilter = CIFilter.CreateRawFilter(imageData, rawOptions); if (ciRawFilter == null) { return; } // Get the native size of the image produced by the CIRawFilter. var sizeValue = ciRawFilter.ValueForKey(Keys.kCIOutputNativeSizeKey) as CIVector; if (sizeValue != null) { imageNativeSize = new CGSize(sizeValue.X, sizeValue.Y); } // Record the original value of the temperature, and setup the editing slider. var tempValue = (NSNumber)ciRawFilter.ValueForKey(Keys.kCIInputNeutralTemperatureKey); if (tempValue != null) { originalTemp = tempValue.FloatValue; TempSlider.SetValue(tempValue.FloatValue, animated: false); } // Record the original value of the tint, and setup the editing slider. var tintValue = (NSNumber)ciRawFilter.ValueForKey(Keys.kCIInputNeutralTintKey); if (tintValue != null) { originalTint = tintValue.FloatValue; TintSlider.SetValue(tintValue.FloatValue, animated: false); } }); // Create EAGL context used to render the CIImage produced by the CIRawFilter to display. ImageView.Context = new EAGLContext(EAGLRenderingAPI.OpenGLES3); ciContext = CIContext.FromContext(ImageView.Context, new CIContextOptions { CIImageFormat = CIImage.FormatRGBAh }); }