Moved example-project into example-folder

This commit is contained in:
DarthAffe committed 2024-03-25 01:09:02 +01:00
1 parent 2dfb072590
commit 37fb19c90c
11 files changed
+1 -1

No files matched your search

@@ -0,0 +1,33 @@
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using StableDiffusion.NET.Helper.Images;
namespace ImageCreationUI.Converter;
[ValueConversion(typeof(IImage), typeof(ImageSource))]
public class ImageToImageSourceConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
Bitmap? bitmap = (value as IImage)?.ToBitmap();
if (bitmap == null) return null;
using MemoryStream ms = new();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
ms.Position = 0;
BitmapImage bitmapImage = new();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
return bitmapImage;
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
}