public static CGColor ToCGColor(this UGColor color) { using (var colorSpace = CGColorSpace.CreateSrgb()) { return(new CGColor(colorSpace, color.ToColorComponents())); } }
public UGRadialGradientBrush(IUGContext context, Vector2 center, float radius, IEnumerable <UGGradientStop> gradientStops, UGEdgeBehavior edgeBehavior) { Center = center; Radius = radius; EdgeBehavior = edgeBehavior; Stops = gradientStops.ToArray(); if (Stops.Length < 2) { throw new ArgumentException(nameof(gradientStops)); } unsafe { var baseFunction = CGFunctionsHelper.GetCGFunction(EdgeBehavior); CGFunction.CGFunctionEvaluate function = (data, outData) => baseFunction(Stops, data, outData); var domain = new nfloat[] { 0, edgeBehavior != UGEdgeBehavior.Clamp ? 1.5F : 1 }; _function = new CGFunction(domain, new nfloat[] { 0, 1, 0, 1, 0, 1, 0, 1 }, function); } var cgCenter = Center.ToCGPoint(); var cgRadius = EdgeBehavior != UGEdgeBehavior.Clamp ? 1.5F * Radius : Radius; using (var colorSpace = CGColorSpace.CreateSrgb()) { _native = CGShading.CreateRadial(colorSpace, cgCenter, 0F, cgCenter, cgRadius, _function, true, true); } }
public IUGContext CreateDrawingSession() { var bpp = 8; var width = (nint)(Scale * Width + .5F); var height = (nint)(Scale * Height + .5F); var stride = 4 * width; var canvasRect = new CGRect(0F, 0F, Width, Height); using (var colorSpace = CGColorSpace.CreateSrgb()) { var context = new CGBitmapContext(null, width, height, bpp, stride, colorSpace, CGImageAlphaInfo.PremultipliedFirst); context.ScaleCTM(Scale, Scale); return(new UGContext(context, canvasRect, Scale, () => { _native = context.ToImage(); context.Dispose(); context = null; })); } }
internal static bool SaveImageWithMetadataiOS13(UIImage image, float quality, NSDictionary meta, string path, string pathExtension) { try { pathExtension = pathExtension.ToLowerInvariant(); var finalQuality = quality; var imageData = pathExtension == "jpg" ? image.AsJPEG(finalQuality) : image.AsPNG(); //continue to move down quality , rare instances while (imageData == null && finalQuality > 0) { finalQuality -= 0.05f; imageData = image.AsJPEG(finalQuality); } if (imageData == null) { throw new NullReferenceException("Unable to convert image to jpeg, please ensure file exists or lower quality level"); } // Copy over meta data using var ciImage = CIImage.FromData(imageData); using var newImageSource = ciImage.CreateBySettingProperties(meta); using var ciContext = new CIContext(); if (pathExtension == "jpg") { return(ciContext.WriteJpegRepresentation(newImageSource, NSUrl.FromFilename(path), CGColorSpace.CreateSrgb(), new NSDictionary(), out var error)); } return(ciContext.WritePngRepresentation(newImageSource, NSUrl.FromFilename(path), CIFormat.ARGB8, CGColorSpace.CreateSrgb(), new NSDictionary(), out var error2)); } catch (Exception ex) { Console.WriteLine($"Unable to save image with metadata: {ex}"); } return(false); }
public static CGColor ToCGColor(Xamarin.Forms.Color color) { return(new CGColor(CGColorSpace.CreateSrgb(), new nfloat[] { (float)color.R, (float)color.G, (float)color.B, (float)color.A })); }
public static CGColor TosRGBCGColor(this Color color) { return(new CGColor(CGColorSpace.CreateSrgb(), new nfloat[] { (float)color.R, (float)color.G, (float)color.B, (float)color.A })); }
static bool SaveImageWithMetadataiOS13(UIImage image, NSDictionary meta, string path, string fileExt) { try { var imageData = fileExt == "png" ? image.AsPNG() : image.AsJPEG(); if (imageData == null) { throw new NullReferenceException("Unable to convert image to jpeg, please ensure file exists or lower quality level"); } // Copy over meta data using (var ciImage = CIImage.FromData(imageData)) using (var newImageSource = ciImage.CreateBySettingProperties(meta)) using (var ciContext = new CIContext()) { if (fileExt == "png") { return(ciContext.WritePngRepresentation(newImageSource, NSUrl.FromFilename(path), CIFormat.ARGB8, CGColorSpace.CreateSrgb(), new NSDictionary(), out var error2)); } return(ciContext.WriteJpegRepresentation(newImageSource, NSUrl.FromFilename(path), CGColorSpace.CreateSrgb(), new NSDictionary(), out var error)); } } catch (Exception ex) { Console.WriteLine($"Unable to save image with metadata: {ex}"); } return(false); }