Perl:将(x,y)像素绘制成单色位图的推荐方法

lex*_*exu 8 perl plot bitmap

对于家庭项目,我需要将(x,y)坐标绘制到400x400黑白位图上.

在OS X,Windows,Linux上,你最容易重复的是什么样的perl模块以及什么样的图像格式(GIF?,PNG?其他?)?


编辑 我的解决方案,基于GD,由Brian Agnew推荐


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);
Run Code Online (Sandbox Code Playgroud)

Bri*_*new 9

看看GD模块(与GD库接口).它使创建图形非常简单,并具有多种输出格式,包括PNG和GIF.