Link to home
Start Free TrialLog in
Avatar of vilusion
vilusion

asked on

Display arraylist in picturebox...

I'll try to explain this as best I can, so here it goes.

I have a scanned image that is normally transferred(displayed) in a new PicForm.  I would like for this scanned image to be displayed in a new PictureBox instead.  Anyhelp would be appreciated.  Here is the code:  This isn't all of the code that scans the image, etc because it would be way too much to paste in here.

Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
            Dim cmd As TwainCommand = tw.PassMessage(m)
            If (cmd = TwainCommand.Not) Then
                Return False
            End If

            Select Case cmd
                Case TwainCommand.CloseRequest
                    EndingScan()
                    tw.CloseSrc()
                Case TwainCommand.CloseOk
                    EndingScan()
                    tw.CloseSrc()
                Case TwainCommand.DeviceEvent
                Case TwainCommand.TransferReady
                    Dim pics As ArrayList = tw.TransferPictures()
                    EndingScan()
                    tw.CloseSrc()
                    picnumber += 1
                    Dim i As Integer
                    For i = 0 To pics.Count - 1 Step 1
                        Dim img As IntPtr = CType(pics(i), IntPtr)
                        Dim newpic As PicForm = New PicForm(img)
                        newpic.MdiParent = Me
                        Dim picnum As Integer = i + 1
                        newpic.Text = "ScanPass" + picnumber.ToString() + "_Pic" + picnum.ToString()
                        newpic.Show()
                    Next
            End Select

            Return True
        End Function
Avatar of vilusion
vilusion

ASKER

Does anyone have any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is the Class function that I have to better help.  I guess the idea I'm trying to solve here is instead of opening the image in a new PicForm, it creates a PictureBox (200px width by 300px height) on my form(frmMain) for each scanned image.  If you need anymore code, just let me know.

Public Function TransferPictures() As ArrayList
            Dim pics As ArrayList = New ArrayList
            If Equals(srcds.Id, IntPtr.Zero) Then
                Return pics
            End If

            Dim rc As TwRC
            Dim hbitmap As IntPtr
            Dim pxfr As TwPendingXfers = New TwPendingXfers()

            Do
                pxfr.Count = 0
                hbitmap = IntPtr.Zero

                Dim iinf As TwImageInfo = New TwImageInfo()
                rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf)
                If (rc <> TwRC.Success) Then
                    CloseSrc()
                    Return pics
                End If

                rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, hbitmap)
                If (rc <> TwRC.XferDone) Then
                    CloseSrc()
                    Return pics
                End If

                rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr)
                If (rc <> TwRC.Success) Then
                    CloseSrc()
                    Return pics
                End If

                pics.Add(hbitmap)
            Loop While (pxfr.Count <> 0)

            rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr)
            Return pics
        End Function