开发者

Fast TIFF image conversion to show in web-client

For preview of scanned TIFF-document currently I 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 FileStreamR开发者_开发百科esult(new MemoryStream(bmpBytes), "image/png");

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

I've found unsafe class which locks and unlocks bitmapData between pixel manipulation here, but I'm not sure that it's suitable for my task (because I need only to transform from one format to another). However my profiler shows about 30ms win (before 116 ms, after 83 ms)


FreeImage is a great image manipulation library, there are C# wrappers for it. You can find the FreeImage .NET documentation too.

Quite mature so several elements of it are highly optimised.


I think i found it! :) Atalasoft dotImage (free edition) boost image showing to about 35ms...


I'm using an external tool for the conversion: http://www.imagemagick.org/script/index.php

It's a lot 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜