-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ImageUpload to Blazor playground
- Loading branch information
Showing
8 changed files
with
92 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using MaterialColorUtilities.Palettes; | ||
using MaterialColorUtilities.Schemes; | ||
using MaterialColorUtilities.Utils; | ||
|
||
namespace Playground.Wasm; | ||
|
||
public partial class MudScheme<TColor> : Scheme<TColor> | ||
{ | ||
public TColor Primary2 { get; set; } = default!; | ||
} | ||
|
||
public class DarkMudSchemeMapper : DarkSchemeMapper<CorePalette, MudScheme<uint>> | ||
{ | ||
protected override void MapCore(CorePalette corePalette, MudScheme<uint> scheme) | ||
{ | ||
base.MapCore(corePalette, scheme); | ||
scheme.Primary2 = scheme.Primary.Add(scheme.OnPrimary, .08); | ||
} | ||
} | ||
|
||
public class LightMudSchemeMapper : LightSchemeMapper<CorePalette, MudScheme<uint>> | ||
{ | ||
protected override void MapCore(CorePalette corePalette, MudScheme<uint> scheme) | ||
{ | ||
base.MapCore(corePalette, scheme); | ||
scheme.Primary2 = scheme.Primary.Add(scheme.OnPrimary, .08); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@using Playground.Wasm.Services | ||
@using SkiaSharp | ||
@using MaterialColorUtilities.Utils | ||
@using System.Runtime.InteropServices | ||
@using MaterialColorUtilities.Palettes | ||
@using System.Diagnostics | ||
|
||
@inject ThemeService ThemeService | ||
|
||
<InputFile id="imageInput" accept="image/png, image/jpeg" hidden OnChange="OnImageSelected" /> | ||
|
||
<MudButton | ||
Variant="Variant.Filled" | ||
HtmlTag="label" | ||
Color="Color.Primary" | ||
for="imageInput"> | ||
Upload image | ||
</MudButton> | ||
|
||
@code { | ||
|
||
private async void OnImageSelected(InputFileChangeEventArgs e) | ||
{ | ||
IBrowserFile resized = await e.File.RequestImageFileAsync("image/png", 122, 122); | ||
using MemoryStream memoryStream = new(); | ||
await using Stream openReadStream = resized.OpenReadStream(); | ||
await openReadStream.CopyToAsync(memoryStream); | ||
memoryStream.Position = 0; | ||
SKBitmap skBitmap = SKBitmap.Decode(memoryStream); | ||
uint[] array = MemoryMarshal.Cast<SKColor, uint>(skBitmap.Pixels).ToArray(); | ||
|
||
uint seed = ImageUtils.ColorsFromImage(array)[0]; | ||
ThemeService.Seed = seed; | ||
} | ||
|
||
} |