Extract small portion of image without loading all

2019-09-03 03:11发布

I have large JPG images ( say 20000x10000 pixels) and want to extract sub-images from these images without loading whole image.

I found it's possible by using this ImageMagick command:

convert -extract 226x248+4216+3377 a.jpg o.jpg

But I need to have it in my C# WPF app.

Magick.NET did not implement extract methods.

Is there any .NET library for this? Or at least a simple exe that can be copied without installing big libs like ImageMagick on client machines.

2条回答
我命由我不由天
2楼-- · 2019-09-03 03:24

Magick.NET does support extraction of a subimage. You should use the Crop method:

using(MagickImage image = new MagickImage("a.jpg"))
{
  image.Crop(new MagickGeometry(226,248,4216,3377));
  image.Write("o,jpg");
}

The -extract option of ImageMagick will read the whole jpg before cropping out the part you need. So maybe this is not a solution for your problem. Only for a small set of formats the image will not be read completely.

查看更多
放荡不羁爱自由
3楼-- · 2019-09-03 03:51

I don't know of any c# libraries that can do this. Gdal at http://www.gdal.org can do it, though. It also has c# wrappers, might be a bit bulky just for this purpose, though.

查看更多
登录 后发表回答