mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 21:24:58 +00:00
Breaking Changes: * `System.Drawing.Common` is dropped and `SixLabors.ImageSharp` is introduced. * uses of `NativeImage.CreateFromBitmap(bitmap, options);` is no longer supported, will cause failed builds. Unexpected Behaviors: * uses ToDataUrl will always create png data urls, unexpected output may happen for those that manipulate this output expecting a different data url format. Obsoletions: * `CreateFromBitmapOptions` & `CreateFromBufferOptions` have been consolidated into `CreateOptions`. Implicit conversions added to ease transition. * `ToBitmapOptions`, `ToDataUrlOptions`, `ToPngOptions` & `BitmapOptions` have been consolidated into `ImageOptions`. Implicit conversions added to ease transition.
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
using SixLabors.ImageSharp;
|
|
|
|
namespace ElectronNET.API.Entities
|
|
{
|
|
internal class NativeImageJsonConverter : JsonConverter
|
|
{
|
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
|
{
|
|
if (value is NativeImage nativeImage)
|
|
{
|
|
var scaledImages = nativeImage.GetAllScaledImages();
|
|
serializer.Serialize(writer, scaledImages);
|
|
}
|
|
}
|
|
|
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
|
{
|
|
var dict = serializer.Deserialize<Dictionary<float, string>>(reader);
|
|
var newDictionary = new Dictionary<float, Image>();
|
|
foreach (var item in dict)
|
|
{
|
|
var bytes = Convert.FromBase64String(item.Value);
|
|
newDictionary.Add(item.Key, Image.Load(new MemoryStream(bytes)));
|
|
}
|
|
return new NativeImage(newDictionary);
|
|
}
|
|
|
|
public override bool CanConvert(Type objectType) => objectType == typeof(NativeImage);
|
|
}
|
|
}
|