【发布时间】:2021-07-23 02:33:33
【问题描述】:
我试图在 WPF 中制作简单的照片编辑器(用于调整亮度、对比度、饱和度等...),并且我使用包含 ToByteArray 方法的 Magick.NET,但问题是我不能用这种方法制作 ByteArray,因为我遇到了异常,因为出于某种原因它不想从 NEF 格式制作 ByteArray...
我的第一个想法是,将 NEF 格式转换为临时 TIFF 文件,该文件可以使用这种特定方法转换为 ByteArray,并且该文件可以转换为 bytearray,但我认为非常不方便且不多聪明。
第二件事是当我拥有 WritableBitmap 时。如何从中制作图像以供 Magick.NET 进行编辑?我应该创建另一个使用已创建的 ByteArray 创建的 MagickImage 实例并编辑该图像吗?
public void ImageSelectBtn_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == true)
{
using (var imageRaw = new MagickImage(dialog.FileName))
{
imageRaw.Write("D:/Coding/C#/New/SoftlightWPF/SoftlightWPF/Resources/temp.tiff");
MagickImage image = new MagickImage();
image = new MagickImage("D:/Coding/C#/New/SoftlightWPF/SoftlightWPF/Resources/temp.tiff");
byte[] ImageBytes = image.ToByteArray();
Render(ImageBytes);
}
}
}
private void Render(byte[] BytesData)
{
using (var ms = new MemoryStream(BytesData))
{
BitmapImage ImageBitmapSource = new BitmapImage(); //Image
ImageBitmapSource.BeginInit();
ImageBitmapSource.CacheOption = BitmapCacheOption.OnLoad;
ImageBitmapSource.StreamSource = ms;
ImageBitmapSource.EndInit();
WriteableBitmap ImageWritableBitmap = new WriteableBitmap(ImageBitmapSource);
this.ImageField.Source = ImageWritableBitmap;
}
}
【问题讨论】:
标签: c# wpf imagemagick magick.net