加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 21:50:37 所属栏目:大数据 来源:网络整理
导读:对于家庭项目,我需要将(x,y)坐标绘制到400×400黑白位图上. 您将重新制作perl模块以及在OS X,Windows,Linux上最容易处理的图像格式(GIF?,PNG?其他?)? 编辑我的解决方案,基于GD,由Brian Agnew推荐 use strict;use warnings;use GD;my $BitMap = GD::Image
对于家庭项目,我需要将(x,y)坐标绘制到400×400黑白位图上.

您将重新制作perl模块以及在OS X,Windows,Linux上最容易处理的图像格式(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);       

# Frame the BitMap
$BitMap->rectangle(0,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);

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读