Quickly convert TIFF images for display in web client

To preview the scanned TIFF document, I currently use the following:

Bitmap bmp = new Bitmap(@"document.tif");
var ms = new MemoryStream();

bmp.Save(ms, ImageFormat.Png);

var bmpBytes = ms.GetBuffer();
bmp.Dispose();
ms.Close();

return new FileStreamResult(new MemoryStream(bmpBytes), "image/png");

Is there a way to speed up the conversion? Using something other than the standard Image.Save () method?

I found an unsafe class that locks and unlocks bitmapData between pixel manipulations here , but I'm not sure if it is suitable for my task (because I only need to convert from one format to another). However, my profiler shows about 30 ms gain (up to 116 ms, after 83 ms)

+3
source share
3 answers
+1

, !:) Atalasoft dotImage ( ) 35 ...

+1

I use an external conversion tool: http://www.imagemagick.org/script/index.php

It is much faster.

Update

Do something like this:

var sourceFile = "C:\\yourscanned.tiff";
var destFile = Path.GetTempPath() + "\\yourpng.tmp";
var process = Process.Start("C:\path\to\imagick\convert.exe", sourceFile + " " + destFile);
process.WaitForExit();

FileStream myStream = new FileStream(destFile);
//woho, do what you want.

File.Delete(destFile);
0
source

Source: https://habr.com/ru/post/1777032/


All Articles