TWAIN ActiveX Control, Plug-in, Scanner SDK, Component, HTTP Control/SDK

Dynamsoft TWAIN Products

Support Community for TWAIN Control/Component/SDK for Scanning Solutions
* Login   * Register
* FAQ    * Search

It is currently Tue May 22, 2012 2:48 am




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: twain.picture sometimes empty
PostPosted: Tue Apr 12, 2005 7:04 am 
Is it possible that twain.Picture is after some few scan empty. Did i forget something, e.g. free some resources.

I have three button:
1. scan with userinterface
2. scan without ui
3. scan multipage (doit by myself - sorry Robert, but the customer has no time to wait ...)
But maybe you can help me (again)

Here is the code ...

Code:
Private Sub cmd_SelectAndAcquire_SinglePageD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_SelectAndAcquire_SinglePageD.Click

    releaseTiff()

    multipage = False
    selectsource()
    twain.OpenSource()
    twain.IfShowUI = False
    twain.EnableSource()

  End Sub

  Private Sub cmd_SelectAndAcquire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_SelectAndAcquire_SinglePage.Click

    releaseTiff()

    multipage = False
    selectsource()
    twain.OpenSource()
    twain.IfShowUI = True
    twain.EnableSource()

  End Sub

  Private Sub cmd_SelectAndAcquire_MultiPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_SelectAndAcquire_MultiPage.Click

    multipage = True
    selectsource()
    releaseTiff()

    Try

      If IO.Directory.Exists("tmpscan") Then ' erstmal das temp Verzeichnis löschen
        IO.Directory.Delete("tmpscan", True)
      End If
      IO.Directory.CreateDirectory("tmpscan") ' dann neu anlegen
      System.Threading.Thread.Sleep(1000)

    Catch ex As Exception
      MessageBox.Show("Fehler in der Methode: " + New StackFrame(True).GetMethod.Name.ToString + " In der Zeile: " + New StackFrame(True).GetFileLineNumber.ToString + _
    System.Environment.NewLine + "Fehler: " + ex.Message)
      Exit Sub
    End Try


    iDocumentCounter = 0

    Try

      twain.OpenSource()
      twain.IfShowUI = False

      twain.IfFeederEnabled = True

      twain.XferCount = -1
      twain.IfAutoFeed = True 'auto feed

      If twain.IfFeederLoaded = True Then
        twain.AcquireImage()
      End If


    Catch ex As Exception

      MessageBox.Show(twain.ErrorString, "Error")

    End Try

  End Sub

  Private Sub selectsource()

    If lstSources.SelectedIndex = -1 Then  'nothing is selected
      Try
        twain.SelectSourceByIndex(0)
      Catch
        MessageBox.Show("Kein Scanner verfügbar")
        Exit Sub
      End Try
    Else
      twain.SelectSourceByIndex(lstSources.SelectedIndex)
    End If

  End Sub

  Private Sub Twain_OnPostTransfer(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles twain.OnPostTransfer

    If multipage Then
      iDocumentCounter += 1

      If twain.SaveAsTiff("tmpscan\tmp" + CStr(iDocumentCounter) + ".tiff") = False Then
        MsgBox(twain.ErrorString)
      End If

      If twain.PendingXfers = 0 Then
        addTiff()
        twain.CloseSource()
        GC.Collect() 'make garbage collector work to release memory

      End If

    Else

      picImageAcquired.Image = twain.Picture
      twain.CloseSource()
      GC.Collect() 'make garbage collector work to release memory

    End If

  End Sub

  Public Sub addTiff()

    newfile = "tmpscan\" & System.Guid.NewGuid.ToString() & ".tif"

    'get the codec for tiff files
    Dim info As ImageCodecInfo = Nothing
    Dim ice As ImageCodecInfo

    For Each ice In ImageCodecInfo.GetImageEncoders()
      If ice.MimeType = "image/tiff" Then info = ice
    Next ice 'use the save encoder

    Dim enc As Encoder = Encoder.SaveFlag
    Dim ep As New EncoderParameters(1)

    ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.MultiFrame))

    Dim pages As Bitmap = Nothing
    Dim frame As Integer = 0

    ' ----------------------------------------------------------------------

    For Each f As String In IO.Directory.GetFiles("tmpscan\", "*." & "tif")

      If frame = 0 Then 'save the first frame
        pages = CType(Image.FromFile(f), Bitmap)
        pages.Save(newfile, info, ep)
      Else 'save the intermediate frames
        ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.FrameDimensionPage))
        Dim bm As Bitmap = CType(Image.FromFile(f), Bitmap)
        pages.SaveAdd(bm, ep)
        bm.Dispose()
      End If

      If frame = iDocumentCounter - 1 Then 'flush and close.
        ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
        pages.SaveAdd(ep)
      End If

      frame += 1

    Next f

    Me.picImageAcquired.Image = Image.FromFile(newfile)
    Me.picImageAcquired.Refresh()

    pages.Dispose()
    pages = Nothing

  End Sub

  Public Sub releaseTiff()

    If Not picImageAcquired.Image Is Nothing Then picImageAcquired.Image.Dispose()
    picImageAcquired.Image = Image.FromFile(Application.StartupPath & "\gotoArchiv.gif")
    If IO.File.Exists(newfile) Then File.Delete(newfile)

  End Sub


Top
  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 8:58 am 
Offline
User avatar

Joined: Mon Mar 07, 2005 11:11 pm
Posts: 866
For the blank image, the possible cause is picImageAcquired.Image.

What is the value of your dpi? If your image size is very big, the Image property in .NET has some problem.

_________________
Robert
TWAIN Support Team
http://www.dynamsoft.com/
TWAIN ActiveX/Plug-in HTTP Control/SDK & TWAIN ActiveX Control, Scanner SDK, Component
Software Configuration Management | SCM Solution


Top
 Profile  
 
 Post subject: empty tiff
PostPosted: Thu Apr 14, 2005 1:12 am 
picturebox comes from infragisitics, but (maybe) inherits from standard ms-picturebox.
dpi-value is normaly 200 (black/white). But I try succesfull colorscans with size up to 8 MB.
The problem at the problem is that's not happen anytime.
What I want to know: Did I make basic (some obvious) errors in my programming.
thx again ...


Top
  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 8:00 am 
Offline
User avatar

Joined: Tue Mar 08, 2005 12:23 am
Posts: 1075
Hi UR-IT,

For the part you are having problem, I can not see anything wrong.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

It is currently Tue May 22, 2012 2:48 am


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Copyright © 2010 Dynamsoft Corporation. All Rights Reserved. | Knowledge Base | Source Control Blog