mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2026-11-10 19:06:31 +00:00
Moved example-project into example-folder
This commit is contained in:
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();
|
||||
}
|
||||
Reference in new issue
Block a user