Forum Replies Created
- AuthorPosts
Ok guys
Ignore my last post. I figure it out. My bit operations were out of wack.
I was checking bit values on a byte using IF statements. For some reason the equality isn’t evaluated as an equality when dealing with bit operators. So, all I did is to modify the code to use a SELECT statements instead (SWITCH equivalent in C# and Java):THIS CODE DIDN’T WORK..!
If objByteRead And (2 ^ (intZ - 1)) = (2 ^ (intZ - 1)) Then
'Bitwise check of bit state (on/off).
objFrame.SetPixel(intCol - intZ, intRow, Color.White)
Else
objFrame.SetPixel(intCol - intZ, intRow, Color.Black)
End If
WHERE AS THIS CODE DID WORK…!
Select Case objByteRead And (2 ^ (intZ - 1))
Case (2 ^ (intZ - 1))
'Bitwise check of bit state (on/off).
objFrame.SetPixel(intCol - intZ, intRow, Color.White)
Case Else
objFrame.SetPixel(intCol - intZ, intRow, Color.Black)
End Select
Hi all again
I have a problem I can’t make any sense out of. While I managed to get the image back in order, the image looks like it was done at a very low resolution. In other words, there are no details.
Any feedback?
Thierry
Thanks for your reply. As it turn out I found out the problem. I was retrieving information from DAT_IMAGEMEMXFER structure in the wrong place. That explains the gibberish I was getting. I now get TWCP_NONE for compression, the expected value. Twain specs makes it clear that TWCP_NONE should be the default behavior.
For those VB.net gurus up there, I finally managed to create a workable piece of code that captures images using BUFFERED MEMORY MODE. So if you need a sample code, post a reply.
Billie
I have a couple of questions. In calling the “DG_IMAGE, DAT_IMAGEMEMXFER, MSG_GET” tripplet, while I managed to get valid data, am having problems putting it together. The “TW_IMAGEMEMXFER” structure returns a value of “278” for compression. Beats me..! I don’t believe that value corresponds to any of the values from Twain:
TWCP_NONE = 0
TWCP_PACKBITS = 1
TWCP_GROUP31D = 2
TWCP_GROUP31DEOL = 3
TWCP_GROUP32D = 4
TWCP_GROUP4 = 5
TWCP_JPEG = 6
TWCP_LZW = 7
TWCP_JBIG = 8
TWCP_PNG = 9
TWCP_RLE4 = 10
TWCP_RLE8 = 11
TWCP_BITFIELDS = 12Is it wise to retrieve the image in compressed format? Wouldn’t that complicate the process of compiling the Tiles/Strips into meaningful bitmaps?
Do you happen to have an example of how to request accepted compression values from the source using capability negotiation?
Hilary
When using Memory Buffer Method, after calling “DG_IMAGE, DAT_IMAGEINFO, MSG_GET” I get a value of 278 for compression. Can’t make a sense out of it. What type of compression is that?
Billie
Thanks a lot. I’ll let you know if have any other questions. Keep an eye.
Unfortunately there are not too many examples of Memory Transfer method.
Billie
Would it be possible for you to post the complete code of your function and any other function called from it? I am trying to make Memory Buffer Method work but am having problems. Would greatly apprectiate it.
I actually solved the problem (thanks for your response, though). But for those who may be curious on how I did it, here is the bottom line (Please, note that including all the code in this forum is a little complicated because it seats all over the place on different files. However, I will try to give you an idea):
From JavaScript I called a method “objScanner.AcquireImage()” of my UserControl “objScanner”. All this method did was to load an instance of my “frmMDI” form:
dim objMDI as new frmMDI
The OnLoad_Event of the MDI form would then create an “objTwain” object where all the calls to TWAIN were coded. Remember from my post that if I skipped the JavaScript code and the UserControl concept altogether and just compiled my application as an executable with the MDI as the startup object and installed on the client computer, all seemed to work fine. So the problem had to do with the right windows handle being passed to Twain. I have a method inside my form:
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
Dim objTwCommand As TwainLib.TW_COMMAND = objTwain.PassMessage(m)
Dim objNextPicture As frmPicture = Nothing
Dim intPictureIndex As Integer = Nothing
Dim objImagePointer As IntPtr = Nothing
Dim araPictures As ArrayList = Nothing
Dim intI As Integer
If objTwCommand = TwainLib.TW_COMMAND.TW_NOT Then
Return False
End If
Select Case objTwCommand
Case TwainLib.TW_COMMAND.TW_CLOSEREQUEST
EndingScan()
objTwain.CloseSrc()
Case TwainLib.TW_COMMAND.TW_CLOSEOK
EndingScan()
objTwain.CloseSrc()
Case TwainLib.TW_COMMAND.TW_DEVICEEVENT
Exit Select
Case TwainLib.TW_COMMAND.TW_TRANSFERREADY
araPictures = objTwain.TransferPictures()
EndingScan()
objTwain.CloseSrc()
intPictureIndex += 1
For intI = 0 To araPictures.Count – 1
objImagePointer = CType(araPictures(intI), IntPtr)
objNextPicture = New frmPicture(objImagePointer)
objNextPicture.MdiParent = Me
intPictureIndex = intI + 1
objNextPicture.Text = “ScanPass” + intPictureIndex.ToString() + “_Pic” + intPictureIndex.ToString()
objNextPicture.Show()
Next
objNextPicture = Nothing
End Select
Return True
End Function… which would intercept all form events (TWAIN and non-TWAIN) and process them accordingly (Reading TWAIN documentation I learned that TWAIN sends all events to my application for pre-processing expecting it to return the favor by sending them back to the “Twain User Interface” for capturing. So if my application failed to capture the events, they would be lost causing the “Twain User Interface” to become unresponsive, which is exactly what happened).
To solve the problem, all I did was, instead of creating a new instance of the MDI form from my UserControl, I called the method:
Application.run(new frmMDI)
…and decorated the method with the “
_” attribute. Basically, this step runs my MDI on its own process avoiding confusion on which handled was passed. I think my interpretation is correct. Sanjeev
Am trying to build the same app using VB.NET. I got it to work fine except for one last bug I will explain below. So, I’ll try to help you with your project. Hopefully, as I state my bug in this forum, someone will care to present an answer.
For starters, check out this website. It will very helpful for your project: http://www.codeproject.com/KB/dotnet/twaindotnet.aspx
You need to build an ActiveX control and deal with all the security settings required for it to work. Don’t worry about any TWAIN required installations on the client. I think most modern operating system do carry all the TWAIN libraries required.
So far, I was able to build the ActiveX Control and send it to the client. When the client, using JavaScript lauches my TWAIN ActiveX, the Source Manager loads successfully no problem. The user is also able to select a TWAIN source. However, after selecting the TWAIN source, while the UI displays with no problem, I can only pre-Scan. All the other options are disabled. The only exception is when I scan and there is no paper in the scanner, where the UI responds with an error message “no paper”.
If I move the code to an executable instead of a DLL, and install it into the client, the program work perfectly. So somehow, the Window Handle gets lost or something. I don’t know.
Hope that helps you.
I mean, what programming language are you using?
Which application are you using to deploy the control?
I don’t know who your clients are, but if they use Windows XP, they should all have twain_32.dll installed on their computers. I am currently building a similar application in ASP.NET. If you go to your forum, you will see my post listed under the title of “Twain Web Control Issue” right after yours. What you should do, if you attempt to deploy the app over the internet (mine is an intranet with all Microsoft Based operating systems), you should run a check on the client’s computer for TWAIN_32.dll.
- AuthorPosts