Dear Monks,

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.


In reply to Importing Bitmaps into PDL by rkosai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.