2026-01-26 14:51:28 +09:00

53 lines
1.7 KiB
C#

/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace VisionCommonUI {
public class BitmapConverter : IValueConverter {
public object Convert(
object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture) {
if (value == null) return null;
BitmapImage image;
using (var memory = new MemoryStream()) {
Bitmap bmp = (Bitmap)value;
bmp.Save(memory, ImageFormat.Bmp);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
image = bitmapImage;
}
return image;
}
private static ImageFormat GetImgFormat(object parameter) {
string format = (string)parameter;
return format == "png" ? ImageFormat.Png
: ImageFormat.Bmp;
}
public object ConvertBack(
object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture) {
throw new NotImplementedException();
}
}
}