如何从 NEF 或其他 RAW 格式制作字节数组并进行编辑?

How can i make byte array from NEF or another RAW Format and edit it?

我正在尝试在 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;
        }
    }

已经有一个图书馆可以帮助您解决这个问题:https://www.nuget.org/packages/Magick.NET.SystemWindowsMedia/。将它添加到您的项目中,然后执行 image.ToBitmapSource()