saraff-9EB1047A4BEB4cef8506B29BA325BD5A / Saraff.Twain.NET

Saraff.Twain.NET is the skillful scanning component which allows you to control work of flatbed scanner, web and digital camera and any other TWAIN device from .NET environment. You can use this library in your programs written in any programming languages compatible with .NET technology.
GNU General Public License v3.0
102 stars 35 forks source link

Saraff Twain SYstem.outOfMemory when aqcuire 50 pages #34

Closed LuisJuarez closed 5 years ago

LuisJuarez commented 5 years ago

HI, im using Saraff twain, it works well with 20, 30 or 40 pages, but when i put 27 sheets (54 pages) an System.OutOfMemory exception is thrown, when i debbug the instance of _twain32 have 54 pages on the buffer, how can i clean the buffer?. I saw i this question a possible solution, and i put on mi code "using" to auto dispose the images, but the problem still.

Im using the EndXfer evento to save the Images on the disk can you tell me if i'm wrong?

private void _twain32_EndXfer(object sender, Twain32.EndXferEventArgs e) { using (var _image = e.Image) { _image.Save(pathImage + "\\" + imC.ToString() + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg); } imC++; //e.Image.Dispose(); }

Thank you

saraff-9EB1047A4BEB4cef8506B29BA325BD5A commented 5 years ago

Hello, @LuisJuarez You can use a IStreamProvider. See https://github.com/saraff-9EB1047A4BEB4cef8506B29BA325BD5A/Saraff.Twain.NET/issues/29#issuecomment-431940887

LuisJuarez commented 5 years ago

Hi again, im using IStreamProvider now but the problem is the same. imagen twian32 instance still storing all the images that it scan, and the exception still showing.

saraff-9EB1047A4BEB4cef8506B29BA325BD5A commented 5 years ago

If you disposing acquired image, memory will be release (even if store reference to image). But I see that you using a MemoryStream for caching a image data. If you wanna acquiring a large number of images you must caching data of acquired image outside the RAM. See a IStreamProvider

LuisJuarez commented 5 years ago

thank you, now i can acquire large number of images :)