+ -
当前位置:首页 → 问答吧 → 请教图像的输出

请教图像的输出

时间:2011-02-05

来源:互联网

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use GD;

  4.         # create a new image
  5. my $im = new GD::Image(100,100);

  6.         # allocate some colors
  7. my $white = $im->colorAllocate(255,255,255);
  8. my $black = $im->colorAllocate(0,0,0);
  9. my $red = $im->colorAllocate(255,0,0);
  10. my $blue = $im->colorAllocate(0,0,255);

  11.         # make the background transparent and interlaced
  12. $im->transparent($white);
  13. $im->interlaced('true');

  14.         # Put a black frame around the picture
  15. $im->rectangle(0,0,99,99,$black);

  16.         # Draw a blue oval
  17. $im->arc(50,50,95,75,0,360,$blue);

  18.         # And fill it with red
  19. $im->fill(50,50,$red);

  20.         # make sure we are writing to a binary stream
  21. binmode STDOUT;


  22. open OUT, "> D:\aaaa.png";
  23. print OUT $im->png;
  24. close OUT;
复制代码
运行之后,报这个:print() on closed filehandle OUT at D:\temp\dzprltmp.pl line 32.      我看不懂了。

本人刚对着perldoc帮助学习用perl作图,有些概念不理解。
图能标准输出么?有个注释# Convert the image to PNG and print it on standard output,自己试了下,结果是乱码。不知道为什么?

作者: 长生天一   发布时间: 2011-02-05



QUOTE:
运行之后,报这个:print() on closed filehandle OUT at D:\temp\dzprltmp.pl line 32.      我看不懂了。 ...
长生天一 发表于 2011-02-05 21:49




try

$file_out = "D:\\aaaa.png";
open OUT, "> $file_out" or die "can't open $file_out\n";
print OUT $im->png;

作者: jason680   发布时间: 2011-02-06