CIColorControls colorCtrls; //CIFilter UIImage AdjustImage(UIImage image) { if (colorCtrls == null) { colorCtrls = new CIColorControls() { Image = CIImage.FromCGImage(image.CGImage) } } ; else { colorCtrls.Image = CIImage.FromCGImage(image.CGImage); } if (context == null) { context = CIContext.FromOptions(null); } colorCtrls.Brightness = sliderB.Value; colorCtrls.Saturation = sliderS.Value; colorCtrls.Contrast = sliderC.Value; using (var outputImage = colorCtrls.OutputImage) { var result = context.CreateCGImage(outputImage, outputImage.Extent); return(UIImage.FromImage(result)); } }
public static NSImage Tint(this NSImage image, NSColor tint) { var colorGenerator = new CIConstantColorGenerator { Color = CIColor.FromCGColor(tint.CGColor) }; var colorFilter = new CIColorControls { Image = (CIImage)colorGenerator.ValueForKey(CIFilterOutputKey.Image), Saturation = 3f, Brightness = 0.35f, Contrast = 1f }; var monochromeFilter = new CIColorMonochrome { Image = CIImage.FromCGImage(image.CGImage), Color = CIColor.FromRgb(0.75f, 0.75f, 0.75f), Intensity = 1f }; var compositingFilter = new CIMultiplyCompositing { Image = (CIImage)colorFilter.ValueForKey(CIFilterOutputKey.Image), BackgroundImage = (CIImage)monochromeFilter.ValueForKey(CIFilterOutputKey.Image) }; var outputImage = (CIImage)compositingFilter.ValueForKey(CIFilterOutputKey.Image); var extent = outputImage.Extent; var newsize = Size.Truncate(extent.Size.ToEto()); if (newsize.IsEmpty) { return(image); } var tintedImage = new NSImage(newsize.ToNS()); tintedImage.LockFocus(); try { var graphics = NSGraphicsContext.CurrentContext.GraphicsPort; var ciContext = CIContext.FromContext(graphics, new CIContextOptions { UseSoftwareRenderer = true }); ciContext.DrawImage(outputImage, extent, extent); } finally { tintedImage.UnlockFocus(); } var newrep = tintedImage.Representations()[0]; newrep.Size = image.Size; tintedImage.Size = image.Size; return(tintedImage); }
void ApplyFilters() { float hue = hueSlider.Value; float saturation = saturationSlider.Value; float brightness = brightnessSlider.Value; // Apply effects to image CIImage result = null; using (var colorControlsFilter = new CIColorControls()) { colorControlsFilter.Image = baseCIImage; colorControlsFilter.Saturation = saturation; colorControlsFilter.Brightness = brightness; result = colorControlsFilter.OutputImage; } using (var hueAdjustFilter = new CIHueAdjust()) { hueAdjustFilter.Image = result; hueAdjustFilter.Angle = hue; result = hueAdjustFilter.OutputImage; } using (var context = CIContext.FromOptions(null)) { using (CGImage cgImage = context.CreateCGImage(result, result.Extent)) { if (imageView.Image != null) { imageView.Image.CGImage.Dispose(); imageView.Image.Dispose(); } imageView.Image = UIImage.FromImage(cgImage); } } result.Dispose(); }
void HandleValueChanged(object sender, EventArgs e) { // use the low-res version if (colorCtrls == null) { colorCtrls = new CIColorControls() { Image = CIImage.FromCGImage(sourceImage.CGImage), } } ; colorCtrls.Brightness = sliderBrightness.Value; colorCtrls.Saturation = sliderSaturation.Value; colorCtrls.Contrast = sliderContrast.Value; var output = colorCtrls.OutputImage; var context = CIContext.FromOptions(null); var result = context.CreateCGImage(output, output.Extent); imageView.Image = UIImage.FromImage(result); // UNCOMMENT to save the image each time it is generated // var someImage = imageView.Image; // someImage.SaveToPhotosAlbum((image, error) => { // // Called on completion... // //new UIAlertView("Saved", "Photo saved to Camera Roll", null, "OK", null).Show (); // Console.WriteLine("CIColorControls image saved to Photos"); // }); } }
CIColorControls colorCtrls; //CIFilter void HandleValueChanged(object sender, EventArgs e) { // use the low-res version if (colorCtrls == null) { colorCtrls = new CIColorControls() { Image = CIImage.FromCGImage(sourceImage.CGImage) } } ; else { colorCtrls.Image = CIImage.FromCGImage(sourceImage.CGImage); } if (context == null) { context = CIContext.FromOptions(null); } colorCtrls.Brightness = sliderBrightness.Value; colorCtrls.Saturation = sliderSaturation.Value; colorCtrls.Contrast = sliderContrast.Value; using (var outputImage = colorCtrls.OutputImage) { var result = context.CreateCGImage(outputImage, outputImage.Extent); imageView.Image = UIImage.FromImage(result); } }
void DarkenImage() { var img = image.Image; var ciImage = new CIImage(img); var hueAdjust = new CIHueAdjust(); // first filter hueAdjust.Image = ciImage; hueAdjust.Angle = 2.094f; var sepia = new CISepiaTone(); // second filter sepia.Image = hueAdjust.OutputImage; // output from last filter, input to this one sepia.Intensity = 0.3f; CIFilter color = new CIColorControls() { // third filter Saturation = 2, Brightness = 1, Contrast = 3, Image = sepia.OutputImage // output from last filter, input to this one }; var output = color.OutputImage; var context = CIContext.FromOptions(null); // ONLY when CreateCGImage is called do all the effects get rendered var cgimage = context.CreateCGImage(output, output.Extent); var ui = UIImage.FromImage(cgimage); image.Image = ui; }
//Filters async void ApplyFilter(FilterType filterType) { if (currentFilterType == filterType) { return; } var filterImage = Element as FilterImage; var handler = GetHandler(filterImage.OriginalSource); using (UIImage originalImage = await handler.LoadImageAsync(filterImage.OriginalSource)) { switch (filterType) { case FilterType.NoFilter: filteredImage = UIImage.FromImage(originalImage.CGImage, originalImage.CurrentScale, originalImage.Orientation); break; case FilterType.BlackAndWhite: var blackAndWhiteEffect = new CIPhotoEffectMono() { Image = new CoreImage.CIImage(originalImage) }; filteredImage = ApplyEffect(blackAndWhiteEffect, originalImage); break; case FilterType.Hifi: var hifiControls = new CIColorControls() { Image = new CoreImage.CIImage(originalImage), Brightness = .5F, // Min: 0 Max: 2 Saturation = 1.2F, // Min: -1 Max: 1 Contrast = 2.5F // Min: 0 Max: 4 }; filteredImage = ApplyEffect(hifiControls, originalImage); break; case FilterType.Vintage: var vintageEffect = new CIPhotoEffectChrome() { Image = new CoreImage.CIImage(originalImage) }; filteredImage = ApplyEffect(vintageEffect, originalImage); break; case FilterType.Saturated: var saturatedEffect = new GPUImageSaturationFilter(); saturatedEffect.Saturation = 2.5f; var imageFiltered = saturatedEffect.CreateFilteredImage(originalImage); filteredImage = imageFiltered; break; } Control.Image = filteredImage; currentFilterType = filterType; } }
public static void Colourize(NSView control, Color color, Action drawAction) { var size = control.Frame.Size; if (size.Width <= 0 || size.Height <= 0) { return; } var image = new NSImage(size); image.LockFocusFlipped(control.IsFlipped); drawAction(); image.UnlockFocus(); var ciImage = CIImage.FromCGImage(image.CGImage); SD.SizeF realSize; if (control.RespondsToSelector(selConvertSizeToBacking)) { realSize = control.ConvertSizeToBacking(size); } else { realSize = control.ConvertSizeToBase(size); } if (control.IsFlipped) { var affineTransform = new NSAffineTransform(); affineTransform.Translate(0, realSize.Height); affineTransform.Scale(1, -1); var filter1 = new CIAffineTransform(); filter1.Image = ciImage; filter1.SetValueForKey(affineTransform, CIInputTransform); ciImage = filter1.ValueForKey(CIOutputImage) as CIImage; } var filter2 = new CIColorControls(); filter2.SetDefaults(); filter2.Image = ciImage; filter2.Saturation = 0.0f; ciImage = filter2.ValueForKey(CIOutputImage) as CIImage; var filter3 = new CIColorMatrix(); filter3.SetDefaults(); filter3.Image = ciImage; filter3.RVector = new CIVector(0, color.R, 0); filter3.GVector = new CIVector(color.G, 0, 0); filter3.BVector = new CIVector(0, 0, color.B); ciImage = filter3.ValueForKey(CIOutputImage) as CIImage; ciImage.Draw(new SD.RectangleF(SD.PointF.Empty, size), new SD.RectangleF(SD.PointF.Empty, realSize), NSCompositingOperation.SourceOver, 1); }
public void End() { if (_image == null) { return; } _image.UnlockFocus(); var cgImage = _image.CGImage; var ciImage = CIImage.FromCGImage(cgImage); #pragma warning disable CS0618 // Image => InputImage in Xamarin.Mac 6.6 var filter2 = new CIColorControls(); filter2.SetDefaults(); filter2.Image = ciImage; filter2.Saturation = 0.0f; ciImage = (CIImage)filter2.ValueForKey(CIOutputImage); var filter3 = new CIColorMatrix(); filter3.SetDefaults(); filter3.Image = ciImage; #pragma warning restore CS0618 var cgColor = Color.ToCG(); var components = cgColor.Components; if (components.Length >= 3) { filter3.RVector = new CIVector(0, components[0], 0); filter3.GVector = new CIVector(components[1], 0, 0); filter3.BVector = new CIVector(0, 0, components[2]); } else if (components.Length >= 1) { // grayscale filter3.RVector = new CIVector(0, components[0], 0); filter3.GVector = new CIVector(components[0], 0, 0); filter3.BVector = new CIVector(0, 0, components[0]); } filter3.AVector = new CIVector(0, 0, 0, cgColor.Alpha); ciImage = (CIImage)filter3.ValueForKey(CIOutputImage); // create separate context so we can force using the software renderer, which is more than fast enough for this var ciContext = CIContext.FromContext(NSGraphicsContext.CurrentContext.GraphicsPort, new CIContextOptions { UseSoftwareRenderer = true }); ciContext.DrawImage(ciImage, new CGRect(CGPoint.Empty, _image.Size), new CGRect(0, 0, cgImage.Width, cgImage.Height)); ciImage.Dispose(); ciContext.Dispose(); filter2.Dispose(); filter3.Dispose(); }
public CIImage ColorControls() { var colorCtrls = new CIColorControls() { Image = flower, Brightness = .5F, // Min: 0 Max: 2 Saturation = 1.2F, // Min: -1 Max: 1 Contrast = 3.1F // Min: 0 Max: 4 }; return(colorCtrls.OutputImage); }
public static void Colourize(NSView control, Color color, Action drawAction) { var size = control.Frame.Size; if (size.Width <= 0 || size.Height <= 0) { return; } var image = new NSImage(size); image.LockFocusFlipped(!control.IsFlipped); drawAction(); image.UnlockFocus(); var ciImage = CIImage.FromCGImage(image.CGImage); CGSize realSize; if (control.RespondsToSelector(selConvertSizeToBacking)) { realSize = control.ConvertSizeToBacking(size); } else { realSize = control.ConvertSizeToBase(size); } var filter2 = new CIColorControls(); filter2.SetDefaults(); filter2.Image = ciImage; filter2.Saturation = 0.0f; ciImage = (CIImage)filter2.ValueForKey(CIOutputImage); var filter3 = new CIColorMatrix(); filter3.SetDefaults(); filter3.Image = ciImage; filter3.RVector = new CIVector(0, color.R, 0); filter3.GVector = new CIVector(color.G, 0, 0); filter3.BVector = new CIVector(0, 0, color.B); filter3.AVector = new CIVector(0, 0, 0, color.A); ciImage = (CIImage)filter3.ValueForKey(CIOutputImage); // create separate context so we can force using the software renderer, which is more than fast enough for this var ciContext = CIContext.FromContext(NSGraphicsContext.CurrentContext.GraphicsPort, new CIContextOptions { UseSoftwareRenderer = true }); ciContext.DrawImage(ciImage, new CGRect(CGPoint.Empty, size), new CGRect(CGPoint.Empty, realSize)); }
public static void ApplyGreyscale(string imagePath, UIImageView imgview) { var uiimage = UIImage.FromFile (imagePath); var ciimage = new CIImage (uiimage); var greyscale = new CIColorControls(); greyscale.Image = ciimage; greyscale.Saturation = 0f; var output = greyscale.OutputImage; var context = CIContext.FromOptions(null); var cgimage = context.CreateCGImage (output, output.Extent); var ui = UIImage.FromImage (cgimage); imgview.Image = ui; }
/// <summary> /// Purchaseable feature. This function can't be called until the /// user has purchased the Greyscale Filter in-app product. /// </summary> public static void ApplyGreyscale(string imagePath, UIImageView imgview) { var uiimage = UIImage.FromFile(imagePath); var ciimage = new CIImage(uiimage); var greyscale = new CIColorControls(); greyscale.Image = ciimage; greyscale.Saturation = 0f; var output = greyscale.OutputImage; var context = CIContext.FromOptions(null); var cgimage = context.CreateCGImage(output, output.Extent); var ui = UIImage.FromImage(cgimage); imgview.Image = ui; }
public override void ViewDidLoad() { base.ViewDidLoad(); displayCup = UIImage.FromFile("CupCloseUp.jpg"); colorContrast = new CIColorControls() { Image = CIImage.FromCGImage(displayCup.CGImage), }; colorContrast.Contrast = 1; var output = colorContrast.OutputImage; var context = CIContext.FromOptions(null); var result = context.CreateCGImage(output, output.Extent); imvDisplayChoice.Image = UIImage.FromImage(result); }
public override void ViewDidLoad() { base.ViewDidLoad(); cup = UIImage.FromFile("CupCloseUp_0.jpg"); imvDisplayChoice.Image = cup; btnChoice.Hidden = false; contrastCtrls = new CIColorControls() { Image = CIImage.FromCGImage(cup.CGImage), }; contrastCtrls.Contrast = 4; var output = contrastCtrls.OutputImage; var context = CIContext.FromOptions(null); var result = context.CreateCGImage(output, output.Extent); imvDisplayChoice.Image = UIImage.FromImage(result); }
public static UIImage AdjustBrightnessSaturationAndContrast(this UIImage image, float brightness = 0, float saturation = 1, float contrast = 1) { CIColorControls colorCtrls = new CIColorControls () { Image = CIImage.FromCGImage (image.CGImage), }; // Clamp values saturation = Math.Min (Math.Max (0, saturation), 2); brightness = Math.Min (Math.Max (-1, brightness), 1); contrast = Math.Min (Math.Max (0, contrast), 4); colorCtrls.Brightness = brightness; colorCtrls.Saturation = saturation; colorCtrls.Contrast = contrast; var output = colorCtrls.OutputImage; var context = CIContext.FromOptions (null); var result = context.CreateCGImage (output, output.Extent); return UIImage.FromImage(result); }
public static UIImage AdjustBrightnessSaturationAndContrast(this UIImage image, float brightness = 0, float saturation = 1, float contrast = 1) { CIColorControls colorCtrls = new CIColorControls() { Image = CIImage.FromCGImage(image.CGImage), }; // Clamp values saturation = Math.Min(Math.Max(0, saturation), 2); brightness = Math.Min(Math.Max(-1, brightness), 1); contrast = Math.Min(Math.Max(0, contrast), 4); colorCtrls.Brightness = brightness; colorCtrls.Saturation = saturation; colorCtrls.Contrast = contrast; var output = colorCtrls.OutputImage; var context = CIContext.FromOptions(null); var result = context.CreateCGImage(output, output.Extent); return(UIImage.FromImage(result)); }
public override void ViewDidLoad() { base.ViewDidLoad(); inActiveTimer = NSTimer.CreateRepeatingScheduledTimer((4.0), delegate { inActive.Play("schudden1.mp3"); }); sourceImage = UIImage.FromFile("drinken_filter.jpg"); imvDisplayChoice.Image = UIImage.FromFile("beker.jpg"); btnTrigger.TouchUpInside += (sender, e) => { inActiveTimer.Dispose(); active.Play("drinken2.mp3"); NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(6.0), delegate { active.Play("drinken2.mp3", () => { //youChoose.Play("dorst.mp3"); }); }); //hid the button. btnTrigger.Hidden = true; imvDisplayChoice.Image = sourceImage; Console.WriteLine("btn pushed"); //puts the picture in an instance to lay a filter on top of it colorBrightness = new CIColorControls() { Image = CIImage.FromCGImage(sourceImage.CGImage), }; int count = 0; timer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromMilliseconds(10), delegate { count++; if (count <= 6) { colorBrightness.Brightness += 0.1f; Console.WriteLine("increase"); } else if (count <= 12) { colorBrightness.Brightness -= 0.1f; Console.WriteLine("decrease"); } else { count = 0; } Console.WriteLine(count); Console.WriteLine(colorBrightness.Brightness); //this will transform the image var output = colorBrightness.OutputImage; var context = CIContext.FromOptions(null); var result = context.CreateCGImage(output, output.Extent); //display result imvDisplayChoice.Image = UIImage.FromImage(result); }); //triggers a timer that displays the old image and makes button visable again NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(12.0), delegate { youChoose.Play("Dorst.mp3", () => { timer.Dispose(); imvDisplayChoice.Image = UIImage.FromFile("beker.jpg"); btnTrigger.Hidden = false; inActiveTimer = NSTimer.CreateRepeatingScheduledTimer((4.0), delegate { inActive.Play("schudden1.mp3"); }); }); }); }; // De SetSatusBarHidden lijkt niet te werken UIApplication.SharedApplication.SetStatusBarHidden(true, true); UIApplication.SharedApplication.IdleTimerDisabled = true; }
public static UIImage ApplyFilter(this UIImage image, float brightness, float saturation, float contrast) { var colorCtrls = new CIColorControls { Image = CIImage.FromCGImage (image.CGImage) }; var context = CIContext.FromOptions (null); // set the values colorCtrls.Brightness = brightness; colorCtrls.Saturation = saturation; colorCtrls.Contrast = contrast; // do the transformation var outputImage = colorCtrls.OutputImage; var result = context.CreateCGImage (outputImage, outputImage.Extent); return UIImage.FromImage (result); }
public override void ViewDidLoad() { base.ViewDidLoad(); btnTrigger.Hidden = false; bekerImage = UIImage.FromFile("bekerDicht.jpg"); imvDisplayChoice.Image = bekerImage; colorContrast = new CIColorControls() { Image = CIImage.FromCGImage(bekerImage.CGImage), }; int count = 0; //default contrast waarde is 1 colorContrast.Contrast = 1; btnUnPushedTimer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1.0), delegate { count++; Console.WriteLine(colorContrast.Contrast); Console.WriteLine(count); if (count <= 6) { colorContrast.Contrast += 0.1f; Console.WriteLine("increase"); } else if (count <= 12) { colorContrast.Contrast -= 0.1f; Console.WriteLine("decrease"); } else { count = 0; } var output = colorContrast.OutputImage; var context = CIContext.FromOptions(null); var result = context.CreateCGImage(output, output.Extent); imvDisplayChoice.Image = UIImage.FromImage(result); }); //een plaatje wisselt met contrast van laag naar hoog en weer terug. //als het contrast van laag naar hoog gaat hoor je een geluidje! (slurp geluid) btnTrigger.TouchUpInside += (sender, e) => { //De knop word hidden btnTrigger.Hidden = true; //als er op de knop gedrukt is gaat het contrast om hoog en blijft het plaatje staan in het hoogste contrast. //tegelijker tijd word de keuze uit gesprooken //als de keuze uit gesprooken is word het scherm voor 5 seconde zwart (zo donker mogelijk). }; }
public CIImage ColorControls () { var colorCtrls = new CIColorControls () { Image = flower, Brightness = .5F, // Min: 0 Max: 2 Saturation = 1.2F, // Min: -1 Max: 1 Contrast = 3.1F // Min: 0 Max: 4 }; return colorCtrls.OutputImage; }
private BlackImagesTheme() { saturationFilter = new CIColorControls(); }
private BlackImagesTheme() { saturationFilter = new CIColorControls (); }
UIImage AdjustImage (UIImage image) { if (colorCtrls == null) colorCtrls = new CIColorControls () { Image = CIImage.FromCGImage (image.CGImage) }; else colorCtrls.Image = CIImage.FromCGImage(image.CGImage); colorCtrls.Brightness = sliderB.Value; colorCtrls.Saturation = sliderS.Value; colorCtrls.Contrast = sliderC.Value; var output = colorCtrls.OutputImage; var context = CIContext.FromOptions (null); var result = context.CreateCGImage (output, output.Extent); return UIImage.FromImage(result); }
CIColorControls colorCtrls; //CIFilter void HandleValueChanged (object sender, EventArgs e) { // use the low-res version if (colorCtrls == null) colorCtrls = new CIColorControls () { Image = CIImage.FromCGImage (sourceImage.CGImage) }; else colorCtrls.Image = CIImage.FromCGImage(sourceImage.CGImage); if (context == null) context = CIContext.FromOptions (null); colorCtrls.Brightness = sliderBrightness.Value; colorCtrls.Saturation = sliderSaturation.Value; colorCtrls.Contrast = sliderContrast.Value; using (var outputImage = colorCtrls.OutputImage) { var result = context.CreateCGImage (outputImage, outputImage.Extent); imageView.Image = UIImage.FromImage (result); } }
void HandleValueChanged(object sender, EventArgs e) { // use the low-res version if (colorCtrls == null) colorCtrls = new CIColorControls () { Image = CIImage.FromCGImage (sourceImage.CGImage), }; colorCtrls.Brightness = sliderBrightness.Value; colorCtrls.Saturation = sliderSaturation.Value; colorCtrls.Contrast = sliderContrast.Value; var output = colorCtrls.OutputImage; var context = CIContext.FromOptions (null); var result = context.CreateCGImage (output, output.Extent); imageView.Image = UIImage.FromImage(result); // UNCOMMENT to save the image each time it is generated // var someImage = imageView.Image; // someImage.SaveToPhotosAlbum((image, error) => { // // Called on completion... // //new UIAlertView("Saved", "Photo saved to Camera Roll", null, "OK", null).Show (); // Console.WriteLine("CIColorControls image saved to Photos"); // }); }
void ApplyFilters() { float hue = hueSlider.Value; float saturation = saturationSlider.Value; float brightness = brightnessSlider.Value; // Apply effects to image CIImage result = null; using(var colorControlsFilter = new CIColorControls ()) { colorControlsFilter.Image = baseCIImage; colorControlsFilter.Saturation = saturation; colorControlsFilter.Brightness = brightness; result = colorControlsFilter.OutputImage; } using(var hueAdjustFilter = new CIHueAdjust ()) { hueAdjustFilter.Image = result; hueAdjustFilter.Angle = hue; result = hueAdjustFilter.OutputImage; } using (var context = CIContext.FromOptions (null)) { using (CGImage cgImage = context.CreateCGImage (result, result.Extent)) { if (imageView.Image != null) { imageView.Image.CGImage.Dispose (); imageView.Image.Dispose (); } imageView.Image = UIImage.FromImage (cgImage); } } result.Dispose (); }