Monday, March 22, 2010

VBA code to import scanned images into...

Hi,



I have to develop a solution that automates the scanning of an image using the TWAIN driver interface. Once scanned, the image appears as a new document in Photoshop where it will be further processed using VBScript scripts.



The solution so far :



Using the freeware 'EZTW32.dll' (copied into C:\WINDOWS\System\), I am able to open the TWAIN scan dialogue on screen, using the function 'TWAIN_AcquireToClipboard(Me.Hwnd, nPixTypes) from the 'EZTW32' dll.



Once the image is scanned, the TWAIN driver is automatically closed, leaving the scanned image on the Windows clipboard.



I then launch Photoshop CS2 using a shell code :

(It is important that Photoshop runs minimized)



Dim strPathname As String

Dim lngShellReturn As Long

Dim appRef As Object

Dim newDocRef



strPathname = ''C:\Program Files\Adobe\Adobe Photoshop CS2\Photoshop.exe''



lngShellReturn = Shell(strPathname, vbMinimizedNoFocus)

Set appRef = CreateObject(''Photoshop.Application'')



When Photoshop is running, then a new document is created and the scanned image is pasted into the document from the Windows clipboard...



Set newDocRef = Documents.Add(8.268, 11.693, 600, ''New Doc'')

newDocRef.Paste



OK, this works up to a point. The newly scanned image appears automatically in Photoshop.



The big problem is that when the user makes a change in resolution or draws a selection box in the TWAIN dialog, this data is not recovered from TWAIN, so the image size parameters in the new document cannot be set.



A beter solution would be to write code that emulates the menu commands in Photoshop CS2:



File -%26gt; Import -%26gt; [Current Scanner]



that launches the TWAIN driver for the current scanner (the code must close TWAIN immediately after scanning). In this case, the resolution and image selection parameters are also imported into the new document.



I am currently refering to the Photoshop CS2 SDK. Do I need to request the Advanced SDK ?



Once beyond this point, then I think I can continue the image processing routines using VBScript as per the SDK.



Any help or other pointers to the TWAIN problem would be VERY APPRECIATED !



Lars
VBA code to import scanned images into...
PLEASE IGNORE MY PREVIOUS POST !



I have now fully resolved the TWAIN problem. It works perfectly and is very robust. I am now continuing with the batch image processing for the newly scanned images using the Photoshop CS2 SDK scripting documents, that I find very detailed, well written, and VERY helpful :)



Peace and love,



Lars

No comments:

Post a Comment