Home › Forums › TWAIN Classic › Image scanned has big size with Python
- This topic has 1 reply, 2 voices, and was last updated 9 years, 4 months ago by MarkM.
- AuthorPosts
I’m trying to scan an image from a scanner with Python.
I used twain library and it works, but the image size is very big at same dpi. When I scan directly with scanner I have an image of (about) 150kb, and when I scan with my application I have an image of (about) 1.50 mb. Someone could help me?I post my simple code:
import twain
sm= twain.SourceManager(0)
ss = sm.OpenSource()
ss.RequestAcquire(0,0)
rv = ss.XferImageNatively()
if rv:
(handle, count) = rv
twain.DIBToBMFile(handle,’imageName.jpg’)Native transfers are always uncompressed images, so your image size will be:
(width-in-inches * dpi) * (height-in-inches * dpi) * bytes-per-pixelMemory, File and MemFile transfers can use compression, like JPEG or Group4, both of which will significantly reduced the size of the image.
Memory transfers are the only ones all drivers must support (aside from native). In the case of JPEG you will almost certainly get a JFIF header, so the image is complete as-is. In the case of Group4, you’ll have to prefix the image data with a TIFF or a PDF wrapper to get a file that can be rendered by a viewer.
- AuthorPosts