Extract small portion of image without loading all of it [closed]

为君一笑 提交于 2019-12-25 02:55:10

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/21423502/extract-small-portion-of-image-without-loading-all-of-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!