- 论坛徽章:
- 0
|
有人写了个GD写BMP文件的代码。
- #! perl -slw
- use strict;
- use GD;
- my $img = GD::Image->newFromJpeg( $ARGV[ 0 ], 1 )
- or die "$ARGV[ 0 ] : $!";
- my( $width, $height ) = $img->getBounds();
- ( my $bmpFile = $ARGV[ 0 ] ) =~ s[.jpg$][.bmp]i;
- open BMP, '>:raw', $bmpFile or die "$bmpFile : $!";
- binmode BMP;
- printf BMP '%s', pack 'A2ISSI', 'BM', $width * $height +54, 0, 0, 54;
- printf BMP '%s', pack 'IiiSSIIiiII',
- 40, $width, $height, 1, 24, 0, $width * $height, 11811, 11811, 0,
- +0;
- for my $y ( reverse 0 .. $height-1 ) {
- for my $x ( 0 .. $width-1 ) {
- printf BMP '%s', pack 'CCC', reverse $img->rgb( $img->getPixel
- +( $x, $y ) );
- }
- }
- close BMP;
复制代码 |
评分
-
查看全部评分
|