Win32-Scanner-EZTWAIN
view release on metacpan or search on metacpan
use Win32::API;
###########################################################################
###
### Define variables for this module
###
###########################################################################
my $twain_select_image_source;
my $twain_acquire_to_file;
my $twain_acquire_to_clipboard;
my $twain_is_available;
my $twain_easy_version;
###########################################################################
###
### Define constants for this module, functions are exported.
###
###########################################################################
sub new {
my $class = shift;
my %parms = @_;
my $self;
my $path_to_dll = "";
if(defined $parms{-dll}) { $path_to_dll = $parms{-dll}; }
$twain_select_image_source = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_SelectImageSource", ['N'], 'N') || croak "Importing API call TWAIN_SelectImageSource failed";
$twain_acquire_to_file = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_AcquireToFilename", ['N', 'P'], 'N') || croak "Importing API call TWAIN_AcquireToFilename failed";
$twain_acquire_to_clipboard = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_AcquireToClipboard", ['N', 'I'], 'N') || croak "Importing API call TWAIN_AcquireToClipboard failed";
$twain_is_available = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_IsAvailable", undef, 'N') || croak "Importing API call TWAIN_IsAvailable failed";
$twain_easy_version = new Win32::API("${path_to_dll}eztw32.dll", "TWAIN_EasyVersion", undef, 'N') || croak "Importing API call TWAIN_EasyVersion failed";
%{$self} = %parms;
bless $self, $class;
return $self;
}
###########################################################################
###
### Methods.
###
###########################################################################
# select_image_source, acquire_to_file and acquire_to_clipboard don't need
# a windows handle. TWAIN wants to defocus and disable the application
# window that called him. According to the documented source file of
# eztw32.dll you may omit the handle. If you omit the handle, eztw32.dll
# will create an invisible proxy window. But what ever you do, don't pass
# the handle of your console window, if you do this anyway, it can really
# screw things up.
sub select_image_source
{
my $self = shift; my $hwnd = 0;
}
sub acquire_to_file
{
my ($self, $file) = @_; my $hwnd = 0;
if(defined $self->{-hwnd}) { $hwnd = $self->{-hwnd}; }
if(!defined $file) { $file = ""; }
return $twain_acquire_to_file->Call($hwnd, $file);
}
sub acquire_to_clipboard
{
my($self, $pixtype) = @_; my $hwnd = 0;
if(defined $self->{-hwnd}) { $hwnd = $self->{-hwnd}; }
if(!defined $pixtype) { $pixtype = TWAIN_ANYTYPE; }
return $twain_acquire_to_clipboard->Call($hwnd, $pixtype);
}
sub is_available { return $twain_is_available->Call(); }
sub easy_version { return sprintf("%.2f", ($twain_easy_version->Call() / 100)); }
1;
__END__
###########################################################################
=item TWAIN_ACQUIRE_WEIRD
Unable to lock DIB, probably an invalid handle (weird).
=item TWAIN_ACQUIRE_ERRWRITEFILE
Writing bitmap to file failed, device full?
=back
=item acquire_to_clipboard($pix_type)
This method starts the scanner user interface and pastes the scanned image
as a bitmap to the windows clipboard. You can force the user interface to
scan the image in a specified pixel type.
Possible pixel types:
=over 4
=item TWAIN_BW
Black and white bitmap, 1-bit per pixel.
=head1 BUGS AND QUIRKS
I noticed that this module doesn't work flawlessly with all scanners, I had
no problems, with my AGFA StudioStar SCSII scanner. On the other hand, the
TWAIN service of my Pinnacle Sys TV card caused some problems. Don't say
I didn't warn you.
=head1 SEE ALSO
C<Win32::Clipboard>, get the scanned image from the clipboard.
=head1 AUTHOR
Lennert Ouwerkerk <lennert@kabelfoon.nl>
=head1 COPYRIGHT
Copyright (C) 2002 Lennert Ouwerkerk. All rights reserved.
=head1 LICENSE
( run in 0.722 second using v1.01-cache-2.11-cpan-84e82930d8c )