def multiScan(self): """ Scan and return an array of PIL objects If no images, will return an empty array """ self.scanner.RequestAcquire(0, 1) images = [] handles = [] try: handle, more = self.scanner.XferImageNatively() handles.append(handle) except twain.excDSTransferCancelled: return [] while more != 0: try: handle, more = self.scanner.XferImageNatively() handles.append(handle) except twain.excDSTransferCancelled: more = 0 for handle in handles: images.append(Image.open(StringIO(twain.DIBToBMfile(handle)))) twain.GlobalHandleFree(handle) return images
import twainsm = twain.sourceManager(0)ss = sm.OpenSource()for i in range(3): //for ex. 3 documents in the scanner device ss.RequestAcquire(0,0) rv = ss.XferImageNatively() if rv: (handle, count) = rv twain.DIBToBMfile(handle, '{i}.bmp'.format(i))
import twainsm = twain.sourceManager(0)sm.SetCallback(onTwainEvent)ss = sm.OpenSource()index = 0for i in range(3): //for ex. 3 documents in the scanner device ss.RequestAcquire(0,0)def onTwainEvent(event): if event == twain.MSG_XFERREADY: saveImage()def saveImage(): rv = ss.XferImageNatively() if rv: (handle, count) = rv twain.DIBToBMfile(handle, '{index}.bmp'.format(index)) index += 1
import twain sm = twain.sourceManager(0) ss = sm.OpenSource() ss.RequestAcquire(0,0) rv = ss.XferImageNatively() if rv: (handle, count) = rv twain.DIBToBMfile(handle, 'image.bmp')
1、降低扫描分辨率、能用灰度就不用彩色、能用24位彩色就不用32位彩色
2、使用自动进纸器
3、采用高压缩比的图像格式,能用jpg就不用tiff,能用tiff就不用bmp
Source.GetCapabilityDefault(CapabilityCode)
Source.GetCapability(CapabilityCode)
Source.GetCapabilityCurrent(CapabilityCode)
Source.SetCapability(CapabilityCode)
Source.resetCapability(CapabilityCode)
Source.GetimageInfo():返回XResolution, YResolution, ImageWIDth, ImageLength, SamplesPerPixel, BitsPerSample, BitsPerPixel, Planar, PixelType, Compression
Source.GetimageLayout():返回((left, top, right, bottom) document_number, page_number, frame_number)
One of the CAP_* (Generic CapabilitIEs), ICAP_ (Image CapabilitIEs)
总结
以上是内存溢出为你收集整理的python twain 扫描全部内容,希望文章能够帮你解决python twain 扫描所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)