Today I spent some time making a few requested enhancements to Help Builder and one thing I wanted to do for a while is add support for doing image capture with SnagIt via its COM interface. One of the really nice features in SnagIt is the object capture (by just clicking on any Screen element) and it's a breeze to implement this and add it to your own applications assuming your customers have SnagIt installed (there's no 'runtime' licensing). However, given that I've recently demo'd this new feature this doesn't seem to be a problem - most of the people either already knew or where already using SnagIt for other things. Bonus!
I haven't used SnagIt all that much primarily because I tend to use PaintShop Pro for image capture mainly because it produces smaller images than any other capture utility I've used. However, I got SnagIt as part of a bundle with CamTasia and decided to install it today, and certainly SnagIt is a wonderful tool for the process of capturing. Anyway, to add this functionality was wonderfully smooth:
Function CaptureImageWithSnagIt
LOCAL oSnag as SnagIt.ImageCapture.1, lcFile
oSnag = CREATEOBJECT("SnagIt.ImageCapture.1")
oSnag.EnablePreviewWindow = .t.
oSnag.Input = 10 && Object
oSnag.Output= 2 && sioFile
oSnag.OutputImageFile.Filename = "captured_Image.png"
oSnag.OutputImageFile.FileType= 5 && siftPNG
IF !EMPTY(this.cSaveDirectory)
oSnag.OutputImageFile.Directory = this.cSavedirectory
ELSE
oSnag.OutputImageFile.Directory = SYS(5) + CURDIR() + "images"
ENDIF
oSnag.OutputImageFile.FileType= 5 && siftPNG
oSnag.Capture()
DO WHILE .t.
if oSnag.IsCaptureDone()
EXIT
ENDIF
DOEVENTS
WAIT WINDOW "" TIMEOUT .01
ENDDO
lcFile = LOWER(oSnag.LastFileWritten)
IF EMPTY(lcFile)
RETURN
ENDIF
*** If EditControl was passed paste into it
IF VARTYPE(THIS.oEditControl) = "O" AND ;
THIS.oEditControl.SelStart = THIS.nEditControlSelStart
this.InsertLink( lcFile,THIS.oEditControl)
ENDIF
oSnag = .F.
This code is part of a class so there are a few references to internal properties, but you should be able to get the general idea here. The odd thing about the interface is that the capture itself is synchronous, but the file save operation is asynchronous. This threw me for a loop as I had a hard time getting the LastFileWritten property retrieved. Waiting in a loop until completed fixed this issue.
Other Posts you might also like