mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2026-11-11 11:26:32 +00:00
Added example application
This commit is contained in:
1 parent
5346e83b84
commit
a198128967
11 files changed
+493
-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