原文:
11.1. Display a bitmap?
Unlike other widgets the Canvas does not take the -bitmap configuration option. One of the ways to place things - including bitmaps - onto a Canvas is to call create on it. To emphasize how a Canvas handles bitmaps differently from the configurable widgets let me assume that you wanted to specify the 'hourglass' built in bitmap in the following. (For more on xbm file specification see a previous question [10.9] within this FAQ.) Here is a way to combine the Canvas; and create; calls: my($canvar) = $main->Canvas(); my($bittag) = $canvar->create('bitmap',10,10, -bitmap=>'hourglass'); $canvar->pack;
You can also create an image that will display a bitmap (plus a whole lot more): my($canvar) = $main->Canvas(); my($bitmap) = $main->Bitmap(-data => $data); my($bittag) = $canvar->create(qw(image 10 10), -image => $bitmap); $canvar->pack; MainLoop;
译文:
11.1 如何在画布中显示位图?
画布不像其它的组件,它不能使用-bitmap的配置选项显示位图。而在画布中设置元素(包括位图)的一个方法是调用create方法。下面我们就假设你想要设置一个内置位图“hourglass”,以此为例向大家解释一下在画布中显示位图有什么不同。(关于xbm文件的问题,请参阅前面的10.9部分)
my($canvar) = $main->Canvas();
my($bittag) = $canvar->create('bitmap',10,10, -bitmap=>'hourglass');
$canvar->pack;
当然,你也可以自己创建位图(还有很多其它的内容):
my($canvar) = $main->Canvas();
my($bitmap) = $main->Bitmap(-data => $data);
my($bittag) = $canvar->create(qw(image 10 10), -image => $bitmap);
$canvar->pack;
MainLoop;