简体   繁体   English

FreeImage dll也不用于批处理

[英]FreeImage dll nor working for batch process

I need to load batches of image files and change their dimensions. 我需要加载一批图像文件并更改其尺寸。 I'm doing it through FreeImage.dll in C++. 我正在通过C ++中的FreeImage.dll进行操作。 Each batch contains JPG and TIF files. 每批包含JPG和TIF文件。 The problem is the exe processes the first batch accurately but for further batches it starts skipping some files, specially JPG files. 问题是exe会准确地处理第一批文件,但对于其他批文件,它会跳过某些文件,尤其是JPG文件。

I tried Initializing and Uninitializing FreeImage before and after each batch but it still doesn't work. 我在每次批处理之前和之后都尝试过初始化和取消初始化FreeImage,但仍然无法正常工作。

Can anybody suggest me the way to do this? 有人可以建议我这样做的方法吗? Even if I'm required to use some other free image processing library that's fine for me. 即使我需要使用其他一些免费的图像处理库对我也很好。

It sounds as if FreeImage is leaking memory or memory gets fragmented in the code calling FreeImage. 听起来好像FreeImage正在泄漏内存,或者在调用FreeImage的代码中内存碎片化了。 Early in the lifetime of your process, enough contiguous memory is still available and everything works fine. 在流程生命周期的早期,仍然有足够的连续内存可用,并且一切正常。 Later on, things start to fail on larger color images. 后来,事情开始在较大的彩色图像上失败。 The reason why specifically jpegs are failing is because the memory image of a color image always takes at least 24 bits per pixel (probably 32 bits), even if its size on disk is much smaller. 特定jpeg失败的原因是,即使彩色图像在磁盘上的大小要小得多,彩色图像的存储图像也总是占用每个像素至少24位(可能是32位)。 Your tiff images are probably black and white and then require only 1 bit per pixel. 您的tiff图片可能是黑白的,因此每个像素仅需要1位。

If not all memory for each processed image is released (either in FreeImage.dll or in your own program), that creates a problem in a continuously running process, even if the amount of memory that stays in use is tiny. 如果没有释放每个处理过的映像的所有内存(在FreeImage.dll或您自己的程序中),那么即使持续使用的内存量很小,这也会在连续运行的过程中产生问题。 The problem is that memory will become fragmented, and the OS cannot relocate the fragments in the memory space of a single process. 问题在于内存将变得碎片化,并且操作系统无法在单个进程的内存空间中重新分配碎片。 For loading large images, large contiguous blocks of memory are required, and in fragmented memory there may not be large enough free "holes" anymore, even if the overall free space is still enough. 为了加载大图像,需要大的连续内存块,并且在碎片化的内存中,即使总的可用空间仍然足够大,也可能没有足够的可用“空洞”。 A simple workaround is to spawn a separate process for each image to be processed and have the main process only doing task management. 一个简单的解决方法是为每个要处理的图像生成一个单独的进程,并使主要进程仅执行任务管理。 This however makes your program slightly more complex and may cause stability problems if it is possible for a worker process to hang. 但是,这会使您的程序稍微复杂些,并且如果工作进程可能挂起,则可能导致稳定性问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM