Add an extensions for SKColorF (#1469)
This commit is contained in:
Родитель
bc2b0a2ace
Коммит
d5d685a580
|
@ -23,7 +23,7 @@ variables:
|
|||
MONO_VERSION_MACOS: 6_8_0
|
||||
MONO_VERSION_LINUX: stable-bionic/snapshots/6.8.0.123
|
||||
XCODE_VERSION: 11.3.1
|
||||
DOTNET_VERSION: 3.1.x
|
||||
DOTNET_VERSION: 3.1.302
|
||||
CONFIGURATION: 'Release'
|
||||
VM_IMAGE_WINDOWS: windows-2019
|
||||
VM_IMAGE_WINDOWS_PREVIOUS: vs2017-win2016
|
||||
|
|
|
@ -55,14 +55,16 @@ namespace SkiaSharp.Views.Forms
|
|||
|
||||
// Xamarin.Forms.Color
|
||||
|
||||
public static Color ToFormsColor(this SKColor color)
|
||||
{
|
||||
return new Color(color.Red / 255.0, color.Green / 255.0, color.Blue / 255.0, color.Alpha / 255.0);
|
||||
}
|
||||
public static Color ToFormsColor(this SKColor color) =>
|
||||
new Color(color.Red / 255.0, color.Green / 255.0, color.Blue / 255.0, color.Alpha / 255.0);
|
||||
|
||||
public static SKColor ToSKColor(this Color color)
|
||||
{
|
||||
return new SKColor((byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255), (byte)(color.A * 255));
|
||||
}
|
||||
public static Color ToFormsColor(this SKColorF color) =>
|
||||
new Color(color.Red, color.Green, color.Blue, color.Alpha);
|
||||
|
||||
public static SKColor ToSKColor(this Color color) =>
|
||||
new SKColor((byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255), (byte)(color.A * 255));
|
||||
|
||||
public static SKColorF ToSKColorF(this Color color) =>
|
||||
new SKColorF((float)color.R, (float)color.G, (float)color.B, (float)color.A);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,10 +62,11 @@ namespace SkiaSharp.Views.Mac
|
|||
|
||||
// CGColor
|
||||
|
||||
public static SKColor ToSKColor(this CGColor color)
|
||||
{
|
||||
return UIColor.FromCGColor(color).ToSKColor();
|
||||
}
|
||||
public static SKColor ToSKColor(this CGColor color) =>
|
||||
UIColor.FromCGColor(color).ToSKColor();
|
||||
|
||||
public static SKColorF ToSKColorF(this CGColor color) =>
|
||||
UIColor.FromCGColor(color).ToSKColorF();
|
||||
|
||||
public static CGColor ToCGColor(this SKColor color)
|
||||
{
|
||||
|
@ -77,19 +78,31 @@ namespace SkiaSharp.Views.Mac
|
|||
#endif
|
||||
}
|
||||
|
||||
public static CGColor ToCGColor(this SKColorF color)
|
||||
{
|
||||
#if __TVOS__ || __WATCHOS__ || __IOS__
|
||||
// see https://bugzilla.xamarin.com/show_bug.cgi?id=44507
|
||||
return UIColor.FromRGBA(color.Red, color.Green, color.Blue, color.Alpha).CGColor;
|
||||
#else
|
||||
return UIColor.FromRgba(color.Red, color.Green, color.Blue, color.Alpha).CGColor;
|
||||
#endif
|
||||
}
|
||||
|
||||
// CIColor
|
||||
|
||||
#if !__WATCHOS__
|
||||
|
||||
public static SKColor ToSKColor(this CIColor color)
|
||||
{
|
||||
return UIColor.FromCIColor(color).ToSKColor();
|
||||
}
|
||||
public static SKColor ToSKColor(this CIColor color) =>
|
||||
UIColor.FromCIColor(color).ToSKColor();
|
||||
|
||||
public static CIColor ToCIColor(this SKColor color)
|
||||
{
|
||||
return new CIColor(color.Red / 255f, color.Green / 255f, color.Blue / 255f, color.Alpha / 255f);
|
||||
}
|
||||
public static SKColorF ToSKColorF(this CIColor color) =>
|
||||
UIColor.FromCIColor(color).ToSKColorF();
|
||||
|
||||
public static CIColor ToCIColor(this SKColor color) =>
|
||||
new CIColor(color.Red / 255f, color.Green / 255f, color.Blue / 255f, color.Alpha / 255f);
|
||||
|
||||
public static CIColor ToCIColor(this SKColorF color) =>
|
||||
new CIColor(color.Red, color.Green, color.Blue, color.Alpha);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,11 +20,19 @@ namespace SkiaSharp.Views.iOS
|
|||
return new SKColor((byte)(r * 255), (byte)(g * 255), (byte)(b * 255), (byte)(a * 255));
|
||||
}
|
||||
|
||||
public static UIColor ToUIColor(this SKColor color)
|
||||
public static SKColorF ToSKColorF(this UIColor color)
|
||||
{
|
||||
return UIColor.FromRGBA(color.Red, color.Green, color.Blue, color.Alpha);
|
||||
System.nfloat r, g, b, a;
|
||||
color.GetRGBA(out r, out g, out b, out a);
|
||||
return new SKColorF((float)r, (float)g, (float)b, (float)a);
|
||||
}
|
||||
|
||||
public static UIColor ToUIColor(this SKColor color) =>
|
||||
UIColor.FromRGBA(color.Red, color.Green, color.Blue, color.Alpha);
|
||||
|
||||
public static UIColor ToUIColor(this SKColorF color) =>
|
||||
UIColor.FromRGBA(color.Red, color.Green, color.Blue, color.Alpha);
|
||||
|
||||
// UIImage
|
||||
|
||||
public static SKImage ToSKImage(this UIImage uiImage)
|
||||
|
|
|
@ -14,11 +14,19 @@ namespace SkiaSharp.Views.Mac
|
|||
return new SKColor((byte)(r * 255), (byte)(g * 255), (byte)(b * 255), (byte)(a * 255));
|
||||
}
|
||||
|
||||
public static NSColor ToNSColor(this SKColor color)
|
||||
public static SKColorF ToSKColorF(this NSColor color)
|
||||
{
|
||||
return NSColor.FromRgba(color.Red, color.Green, color.Blue, color.Alpha);
|
||||
System.nfloat r, g, b, a;
|
||||
color.GetRgba(out r, out g, out b, out a);
|
||||
return new SKColorF((float)r, (float)g, (float)b, (float)a);
|
||||
}
|
||||
|
||||
public static NSColor ToNSColor(this SKColor color) =>
|
||||
NSColor.FromRgba(color.Red, color.Green, color.Blue, color.Alpha);
|
||||
|
||||
public static NSColor ToNSColor(this SKColorF color) =>
|
||||
NSColor.FromRgba(color.Red, color.Green, color.Blue, color.Alpha);
|
||||
|
||||
|
||||
// NSImage
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче