Magick.NET convert raw images

2.3k Views Asked by At

I use Magick.NET for processing files. And now I need convert raw image format (such as .dng, .3fr, .cr2, .raw, .ptx, etc.) to simple jpg for generating preview on the site. I found example in documentation here but it's not working. I put dcraw.exe to Magick.NET dll's but always got error in this moment:

//code
using (var originalImg = new MagickImage(abspath))...
//text of error
InnerException = {"iisexpress.exe: FailedToExecuteCommand `dcraw.exe -6 -w -O \"C:/Users/A8F50~1.CHE/AppData/Local/Temp/magick-29445L9OLy_DVIQq.ppm\" \"C:/Users/A8F50~1.CHE/AppData/Local/Temp/magick-294458yvxz2HRaYX\"' (-1) @ error/delegate.c/ExternalDelegateCommand/484"}
Message = "iisexpress.exe: UnableToOpenBlob 'C:/Users/A8F50~1.CHE/AppData/Local/Temp/magick-29445L9OLy_DVIQq.ppm': No such file or directory @ error/blob.c/OpenBlob/2684"

Is anyone faced with such problem? I have no idea why this shit happens. I wasted a lot of time for this and I'll be glad if you'll help me with this problem

2

There are 2 best solutions below

1
On

you have to use a FileStream object instead the file path... That will work for me.

Try this:

FileStream fileStream = new FileStream(@"C:\QRcodes\IMG_9540.CR2", FileMode.Open);

        using (MagickImage magickImage = new MagickImage(fileStream))
        {
            byte[] imageBytes = magickImage.ToByteArray();

            Console.WriteLine("bytes in image: " + imageBytes.Length);
            Console.ReadKey();
        }

greetings Markus

0
On

This is not related to the file stream or actual physical path. you can call the MagickImage constructor with a physical path. The problem and the error message you received is that your code cannot find the file. It may be because of the permission or the way you pass the address of the file or any thing that prevent your code to reach the file. One another things: Converting the MagickImage to ByteArray is highly time consuming and is heavy process in the system. If you try an image with 20000 pixels you will see the result.