Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SKFilteredImage and related #103

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions samples/SkiaSharpDemo.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(bundle);

Xamarin.Essentials.Platform.Init(this, bundle);
Expand Down
8 changes: 4 additions & 4 deletions samples/SkiaSharpDemo.Android/SkiaSharpDemo.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="HarfBuzzSharp" Version="2.6.1.6" />
<PackageReference Include="SkiaSharp" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.80.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.80.2" />
<PackageReference Include="Xamarin.Essentials" Version="1.6.0-pre1" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1364" />
<PackageReference Include="Topten.RichTextKit" Version="0.3.133" />
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions samples/SkiaSharpDemo.UWP/SkiaSharpDemo.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="HarfBuzzSharp" Version="2.6.1.6" />
<PackageReference Include="SkiaSharp" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.80.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.80.2" />
<PackageReference Include="Xamarin.Essentials" Version="1.6.0-pre1" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1364" />
<PackageReference Include="Topten.RichTextKit" Version="0.3.133" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.10" />
Expand Down
8 changes: 4 additions & 4 deletions samples/SkiaSharpDemo.WPF/SkiaSharpDemo.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

<ItemGroup>
<PackageReference Include="HarfBuzzSharp" Version="2.6.1.6" />
<PackageReference Include="SkiaSharp" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views.Forms.WPF" Version="2.80.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views.Forms.WPF" Version="2.80.2" />
<PackageReference Include="Xamarin.Essentials" Version="1.6.0-pre1" />
<PackageReference Include="Xamarin.Forms.Platform.WPF" Version="4.8.0.1364" />
<PackageReference Include="Topten.RichTextKit" Version="0.3.133" />
</ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions samples/SkiaSharpDemo.iOS/SkiaSharpDemo.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<RootNamespace>SkiaSharpDemo.iOS</RootNamespace>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<AssemblyName>SkiaSharpDemo.iOS</AssemblyName>
<BuildIpa>true</BuildIpa>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -70,10 +71,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="HarfBuzzSharp" Version="2.6.1.6" />
<PackageReference Include="SkiaSharp" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.80.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.80.2" />
<PackageReference Include="Xamarin.Essentials" Version="1.6.0-pre1" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1364" />
<PackageReference Include="Topten.RichTextKit" Version="0.3.133" />
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions samples/SkiaSharpDemo.macOS/SkiaSharpDemo.macOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="HarfBuzzSharp" Version="2.6.1.6" />
<PackageReference Include="SkiaSharp" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views" Version="2.80.1" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.80.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="2.80.2" />
<PackageReference Include="Xamarin.Essentials" Version="1.6.0-pre1" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1364" />
<PackageReference Include="Topten.RichTextKit" Version="0.3.133" />
</ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions samples/SkiaSharpDemo/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@

<converters:RoundToIntConverter x:Key="RoundToInt" />
<converters:RoundToConverter x:Key="RoundTo" />
<converters:DebugConverter x:Key="Debug" />
<converters:EnabledOpacityConverter x:Key="EnabledOpacity" />
<converters:EnabledDisabledConverter x:Key="EnabledDisabled" />

<Style TargetType="Page" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="White" />
</Style>

<Style TargetType="StackLayout">
<Setter Property="Spacing" Value="0" />
<Setter Property="Padding" Value="0" />
Expand All @@ -22,6 +29,12 @@
<Setter Property="Padding" Value="0" />
</Style>

<Style TargetType="Slider">
<Setter Property="MinimumTrackColor" Value="Accent" />
<Setter Property="MaximumTrackColor" Value="Gray" />
<Setter Property="ThumbColor" Value="Accent" />
</Style>

<!-- OptionButton styles -->
<ResourceDictionary>
<Style x:Key="OptionButtonStyle" TargetType="Button">
Expand Down
2 changes: 1 addition & 1 deletion samples/SkiaSharpDemo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class App : Application
{
public App()
{
Device.SetFlags(new[] { "CarouselView_Experimental" });
Device.SetFlags(new[] { "CarouselView_Experimental", "SwipeView_Experimental" });

InitializeComponent();

Expand Down
20 changes: 20 additions & 0 deletions samples/SkiaSharpDemo/Converters/DebugConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using Xamarin.Forms;

namespace SkiaSharpDemo.Converters
{
public class DebugConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return value;

return value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
value;
}
}
15 changes: 15 additions & 0 deletions samples/SkiaSharpDemo/Converters/EnabledDisabledConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Globalization;
using Xamarin.Forms;

namespace SkiaSharpDemo.Converters
{
public class EnabledDisabledConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is bool enabled && enabled ? "Disable" : "Enable";

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
}
15 changes: 15 additions & 0 deletions samples/SkiaSharpDemo/Converters/EnabledOpacityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Globalization;
using Xamarin.Forms;

namespace SkiaSharpDemo.Converters
{
public class EnabledOpacityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is bool enabled && enabled ? 1.0 : 0.5;

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
}
27 changes: 12 additions & 15 deletions samples/SkiaSharpDemo/Demos/BlurHash/BlurHashPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SkiaSharp;
using SkiaSharp.Extended;
using SkiaSharp.Views.Forms;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace SkiaSharpDemo.Demos
Expand Down Expand Up @@ -161,24 +162,20 @@ private async Task UpdateBlur()

private async void OnPickImage()
{
//var options = new MediaPickerOptions
//{
// Title = "Custom Image",
//};

//var picker = MediaPicker.IsCaptureSupported
// ? MediaPicker.CapturePhotoAsync(options)
// : MediaPicker.PickPhotoAsync(options);
var options = new MediaPickerOptions
{
Title = "Custom Image",
};

//var image = await picker;
var image = await MediaPicker.PickPhotoAsync(options);

//if (image != null)
//{
// var newSource = new StreamImageSource { Stream = _ => image.OpenReadAsync() };
if (image != null)
{
var newSource = new StreamImageSource { Stream = _ => image.OpenReadAsync() };

// Sources[Sources.Count - 1] = newSource;
// Source = newSource;
//}
Sources[Sources.Count - 1] = newSource;
Source = newSource;
}
}
}
}
16 changes: 4 additions & 12 deletions samples/SkiaSharpDemo/Demos/Confetti/ConfettiPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@
HorizontalOptions="End" VerticalOptions="Center" />
<Slider Maximum="500" Minimum="10" Value="{Binding CurrentConfig.MinSpeed, Converter={StaticResource RoundToInt}}"
Grid.Column="1" Grid.Row="0"
VerticalOptions="Center"
MinimumTrackColor="Accent" MaximumTrackColor="Accent"
ThumbColor="Accent" />
VerticalOptions="Center" />
<Label Text="{Binding CurrentConfig.MinSpeed}"
Grid.Column="2" Grid.Row="0"
HorizontalOptions="Start" VerticalOptions="Center" />
Expand All @@ -112,9 +110,7 @@
HorizontalOptions="End" VerticalOptions="Center" />
<Slider Maximum="500" Minimum="10" Value="{Binding CurrentConfig.MaxSpeed, Converter={StaticResource RoundToInt}}"
Grid.Column="1" Grid.Row="1"
VerticalOptions="Center"
MinimumTrackColor="Accent" MaximumTrackColor="Accent"
ThumbColor="Accent" />
VerticalOptions="Center" />
<Label Text="{Binding CurrentConfig.MaxSpeed}"
Grid.Column="2" Grid.Row="1"
HorizontalOptions="Start" VerticalOptions="Center" />
Expand All @@ -128,9 +124,7 @@
HorizontalOptions="End" VerticalOptions="Center" />
<Slider Maximum="6" Minimum="0" Value="{Binding CurrentConfig.Lifetime, Converter={StaticResource RoundTo}, ConverterParameter=1}"
Grid.Column="1" Grid.Row="0"
VerticalOptions="Center"
MinimumTrackColor="Accent" MaximumTrackColor="Accent"
ThumbColor="Accent" />
VerticalOptions="Center" />
<Label Text="{Binding CurrentConfig.Lifetime, StringFormat='{}{0}s'}"
Grid.Column="2" Grid.Row="0"
HorizontalOptions="Start" VerticalOptions="Center" />
Expand All @@ -140,9 +134,7 @@
HorizontalOptions="End" VerticalOptions="Center" />
<Slider Maximum="6" Minimum="0" Value="{Binding CurrentConfig.Duration, Converter={StaticResource RoundTo}, ConverterParameter=1}"
Grid.Column="1" Grid.Row="1"
VerticalOptions="Center"
MinimumTrackColor="Accent" MaximumTrackColor="Accent"
ThumbColor="Accent" />
VerticalOptions="Center" />
<Label Text="{Binding CurrentConfig.Duration, StringFormat='{}{0}s'}"
Grid.Column="2" Grid.Row="1"
HorizontalOptions="Start" VerticalOptions="Center" />
Expand Down
4 changes: 1 addition & 3 deletions samples/SkiaSharpDemo/Demos/Extended/InterpolationPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
<StackLayout Spacing="12">

<Label Text="{Binding Interpolation, StringFormat='{}{0:0}%'}" HorizontalOptions="Center" />
<Slider Minimum="0" Maximum="100" Value="{Binding Interpolation}"
MinimumTrackColor="Black" MaximumTrackColor="Black"
ThumbColor="Black" />
<Slider Minimum="0" Maximum="100" Value="{Binding Interpolation}" />

<Button Text="Toggle Animation" Command="{Binding AnimateCommand}" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms;

namespace SkiaSharpDemo.Demos
{
public class FilterDataTemplateSelector : DataTemplateSelector
{
public FilterDataTemplateCollection Templates { get; } = new FilterDataTemplateCollection();

public DataTemplate? Unknown { get; set; }

protected override DataTemplate? OnSelectTemplate(object item, BindableObject container)
{
if (item != null)
{
var type = item.GetType();
var template = Templates.FirstOrDefault(t => t.FilterType == type)?.Template;
if (template != null)
return template;
}

return Unknown;
}
}

public class FilterDataTemplateCollection : List<FilterDataTemplate>
{
}

[ContentProperty(nameof(Template))]
public class FilterDataTemplate : BindableObject
{
public Type? FilterType { get; set; }

public DataTemplate? Template { get; set; }
}
}
Loading