$dc->Image('briefpapier.png', 0, 0);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Umwandeln einer Grafik in einen String open MYFILE, 'bild.png' or die "Cannot open file: $!"; binmode MYFILE; my $rawdata; while (<MYFILE>) { $rawdata .= $_; } close MYFILE; my $bildstring = encode_base64($rawdata); # Diesen String als Bild verwenden: $mw->Photo( -data => $bildstring );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
sub Image { my $self = shift; if (($#_ != 0) and ($#_ != 2) and ($#_ != 4)) { _croak "ERROR: Wrong number of parameters!\n"; return undef; } my ($width, $height) = (0, 0); if (($#_ == 2) or ($#_ == 4)) { my ($fileorref, $x, $y, $w, $h) = @_; if (!_IsNo($fileorref)) { $fileorref = $self->Image($fileorref); unless (defined($fileorref)) { return undef; } } _GetEnhSize($self->{dc}, $fileorref, $width, $height, $self->{unit}); $width = $self->_xp2un($width); $height = $self->_yp2un($height); if ((!defined($w)) or ($w == 0)) { $w = $width; } if ((!defined($h)) or ($h == 0)) { $h = $height; } unless (_PlayEnhMetaFile($self->{dc}, $fileorref, $self->_xun2p($x), $self->_yun2p($y), $self->_xun2p($x + $w), $self->_yun2p($y + $h))) { _croak "ERROR: Cannot display metafile! ${\_GetLastError()}"; return undef; } return wantarray ? ($fileorref, $width, $height) : $fileorref; } else { my $file = shift; if (_IsNo($file)) { _GetEnhSize($self->{dc}, $file, $width, $height, $self->{unit}); $width = $self->_xp2un($width); $height = $self->_yp2un($height); return ($width, $height); } if (defined($self->{imagef}->{$file})) { _GetEnhSize($self->{dc}, $self->{imagef}->{$file}, $width, $height, $self->{unit}); $width = $self->_xp2un($width); $height = $self->_yp2un($height); return wantarray ? ($self->{imagef}->{$file}, $width, $height) : $self->{imagef}->{$file}; } my $fref; if ($file =~ /.emf$/) { $fref = _GetEnhMetaFile($file); unless ($fref) { _croak "ERROR: Cannot load metafile! ${\_GetLastError()}"; return undef; } } elsif ($file =~ /.wmf$/) { $fref = _GetWinMetaFile($self->{dc}, $file); unless ($fref) { _croak "ERROR: Cannot load metafile! ${\_GetLastError()}"; return undef; } } else { $fref = _LoadBitmap($self->{dc}, $file, -1, $self->{unit}); unless ($fref) { _croak "ERROR: Cannot load bitmap! ${\_GetLastError()}"; return undef; } } $self->{imager}->{$fref} = $file; $self->{imagef}->{$file} = $fref; _GetEnhSize($self->{dc}, $fref, $width, $height, $self->{unit}); $width = $self->_xp2un($width); $height = $self->_yp2un($height); return wantarray ? ($fref, $width, $height) : $fref; } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Tk::Error: ERROR: Cannot load bitmap! Fehler beim Einlagern einer Speicherseite.
at Z:\Development Sync\RFK\rfk.pl line 11133
Carp::croak at C:/Perl/lib/Carp.pm line 44
Win32::Printer::_croak at C:/Perl/site/lib/Win32/Printer.pm line 122
Win32::Printer::Image at C:/Perl/site/lib/Win32/Printer.pm line 2477
Win32::Printer::Image at C:/Perl/site/lib/Win32/Printer.pm line 2422
main::rechnungen_print_kopf at Z:\Development Sync\RFK\rfk.pl line 11133
main::rechnungen_print at Z:\Development Sync\RFK\rfk.pl line 11034
main::__ANON__ at Z:\Development Sync\RFK\rfk.pl line 9950
Tk callback for .toplevel.frame.button3
Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 250
Tk::Button::butUp at C:/Perl/site/lib/Tk/Button.pm line 175
<ButtonRelease-1>
(command bound to event)
perldoc Win32::Printer...
Natively it supports EMF and WMF format files. BMP, CUT, DDS, ICO, JPEG, JNG, KOALA, LBM, IFF, MNG, PBM, PBMRAW, PCD, PCX, PGM, PGMRAW, PNG, PPM, PPMRAW, PSD, RAS, TARGA, TIFF, WBMP, XBM, XPM bitmap formats are handled via FreeImage library.
http://search.cpan.org/~wasx/Win32-Printer-0.9.1/Printer.pm#INSTALLATION...
INSTALLATION
...
3. For bitmap support, copy FreeImage.dll somewhere in your system path. You may get this library form http://sourceforge.net/.
...
StretchDIBits(hdc, 0, 0, lpbmi->bmiHeader.biWidth, lpbmi->bmiHeader.biHeight, 0, 0, lpbmi->bmiHeader.biWidth, lpbmi->bmiHeader.biHeight, (CONST VOID *) FreeImage_GetBits(Image), lpbmi, DIB_RGB_COLORS, SRCCOPY)