rkosai has asked for the wisdom of the Perl Monks concerning the following question:
I was wondering everyone's opinions on the best way of importing bitmaps into a PDL array (this is called a piddle, right?) on Win32 systems.
A little background:
I have a script that uses Win32::API to make various API calls to avicap32.dll, gdi32.dll, and others in order to capture still images from a webcam. I then use another API call to copy it to the clipboard, where I use Win32::Clipboard to get the image. I would like to use PDL to perform some image manipulation on the image, but unfortunately this image is in bitmap (bmp) format. Looking through prior nodes, I checked for bitmap support using the PDL::IO::Pic module as suggested in the node PDL examples?. I use:
use PDL::IO::Pic;
print join ', ', PDL->wpiccan();
And get the output:
PNM
This indicates that bitmaps are not on the list of supported types (along with GIFs, JPEGs, TIFs, etc, making me suspect my PDL module installed via PPM). I also looked for a bitmap module on CPAN, but didn't see any that would help import bitmap contents, even after a good amount of searching.
Are there any monks familiar with this problem, or who have solutions? Perhaps a neat unpack trick after stripping headers? Any help is appreciated.
Also, this is my first post here on Perl Monks, but I've been an anonymous reader for the last two years. I would appreciate it if any monks would tell me of any improper formatting or conventions of my post.
Code Enclosed for any who might find it useful:
#!/usr/bin/perl use strict; use Win32::API; use Win32::Clipboard; ############################################# ## MAIN BLOCK ## ############################################# print "Using device: " . getDeviceList() . "...\n"; captureImage(0); print "DONE!\n"; ############################################# ## SUBROUTINES ## ############################################# sub getDeviceList { my $device = ''; my $strName = " " x 100; #necessary for the API call my $strVer = " " x 100; my $i = 0; my $driverGet = new Win32::API('avicap32.dll', 'capGetDriverDescript +ionA', 'IPIPI', 'I'); if($driverGet->Call($i, $strName, 100, $strVer, 100)) { #make API ca +ll to find devices $strName = unpack('A*', $strName); #trim trailing nulls $device = $strName; } return ($device ? $device : "Error - No device found"); #if theres a + device, show it } sub captureImage { my $iDevice = shift; my $getD = new Win32::API('user32.dll', 'GetDesktopWindow', '', 'N') +; my $desktopHwnd = $getD->Call(); #need the desktop handle my $cCreate = new Win32::API('avicap32.dll', 'capCreateCaptureWindow +A', 'PIIIIIII', 'I'); my $sMsg = new Win32::API('user32.dll', 'SendMessageA', 'IIIP', 'I') +; my $wDestroy = new Win32::API('user32.dll', 'DestroyWindow', 'I', 'I +'); my $wDC = new Win32::API('gdi32.dll', 'CreateCompatibleDC', 'N', 'N' +); #create memory DC as a temporary workspace my $memHwnd = $wDC->Call($desktopHwnd); my $handle = $cCreate->Call($iDevice, 0, 0, 0, 640, 480, $memHwnd, 0 +); #Invisible if ($sMsg->Call($handle, 1034, $iDevice, 0)) { #if DRIVER_CONNECT $sMsg->Call($handle, 1077, 1 , 0); print "Scale Set...\n"; $sMsg->Call($handle, 1074, 1, 0); print "Previewing...\n"; $sMsg->Call($handle, 1076, 1, 0); print "Preview Rate...\n"; $sMsg->Call($handle, 1054, 0, 0); print "Copying...\n";#copy to cl +ipboard sleep 1; $wDestroy->Call($handle); } else { print "Device invalid or in use.\n"; $wDestroy->Call($handle); } #save the clipboard to file my $image = Win32::Clipboard::GetBitmap(); open (BITMAP, ">current_image.bmp"); binmode (BITMAP); print BITMAP $image; close (BITMAP); }
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Importing Bitmaps into PDL
by tachyon (Chancellor) on Sep 13, 2004 at 01:53 UTC |