2009-07-25 13 views
8

ホームプロジェクトでは、(x、y)座標を400x400の白黒ビットマップにプロットする必要があります。Perl:(x、y)ピクセルをモノクロビットマップにプロットする方法

どのような画像フォーマット(GIF、PNG?その他)をOS X、Windows、Linuxで扱うのが最も簡単でしょうか?


EDIT私のソリューション、GDに基づいて、ブライアンアグニューによって


use strict; 
use warnings; 
use GD; 
my $BitMap = GD::Image->new(400,400); 

my $white = $BitMap->colorAllocate(255,255,255); 
my $black = $BitMap->colorAllocate(0,0,0);  

# Frame the BitMap 
$BitMap->rectangle(0,0,399,399,$black); 
# Transparent image, white background color 
$BitMap->transparent($white); 

# plot some, just to show it works # 
for my $x (0..100) { 
    for my $y (0 .. 100) { 
     $BitMap->setPixel(250+100*sin($x)-$y,150+125*cos($x)+$y,$black); 
    } 
} 

# write png-format to file 
open my $fh,">","test.png" or die "$!"; 
binmode $fh; 
print $fh $BitMap->png; 
close($fh); 

答えて

9

をお奨めとしては、(GD libraryへのインタフェース)GD moduleを見てください。これは、グラフィックスの作成を非常に簡単にし、PNGやGIFを含む幅広い出力フォーマットを持っています。

関連する問題