NAME
Image::Base::Tk::Canvas -- draw into Tk::Canvas
SYNOPSIS
use Image::Base::Tk::Canvas;
my $image = Image::Base::Tk::Canvas->new (-width => 100,
-height => 100);
$image->rectangle (0,0, 99,99, 'white');
$image->xy (20,20, 'black');
$image->line (50,50, 70,70, '#FF00FF');
$image->line (50,50, 70,70, '#0000AAAA9999');
$image->save ('/some/filename.eps');
CLASS HIERARCHY
Image::Base::Tk::Canvas
is a subclass of Image::Base
,
Image::Base
Image::Base::Tk::Canvas
DESCRIPTION
Image::Base::Tk::Canvas
extends Image::Base
to add items to a Tk::Canvas
widget. There's no file reading, but encapsulated postscript (EPS) can be written.
Tk::Canvas
has more features than are available here, but this module is a novel way to point some Image::Base
code at a canvas. In principle there's no limit on how many items a canvas can hold, but if drawing lots of individual pixels then Tk::Photo
and Image::Base::Tk::Photo
may be better.
Colours
Colour names are anything recognised by Tk_GetColor(3tk), which means X11 style
X server F<rgb.txt> names
#RGB hex
#RRGGBB hex
#RRRGGGBBB hex
#RRRRGGGGBBBB hex
Like Xlib, the shorter hex forms are padded with zeros, so "#FFF" means only "#F000F000F000", which is a light grey rather than white.
FUNCTIONS
$image = Image::Base::Tk::Canvas->new (key=>value,...)
-
Create and return a new canvas image object. A new canvas can be created with
-width
,-height
, and a-for_widget
which is its parent$image = Image::Base::Tk::Canvas->new (-for_widget => $parent, -width => 200, -height => 100);
Or an existing
Tk::Canvas
object can be given,$image = Image::Base::Tk::Canvas->new (-tkcanvas => $tkcanvas);
$colour = $image->xy ($x, $y)
$image->xy ($x, $y, $colour)
-
Get or set an individual pixel. Setting an individual pixel adds a 1x1 rectangle.
Getting a pixel is currently implemented by looking for an item at
$x,$y
and picking out its colour. This works well enough for the item types added by this module but may be wrong for others, in particular an item outline is not distinguished from its fill interior. "window" items are read with aTk::WinPhoto
and may be a bit slow (and might even induce an Xlib error if the window is off the edges of the screen). "bitmap" items are not read at all yet. $image->diamond ($x0, $y0, $x1, $y1, $colour)
-
Draw a diamond shape within the rectangle top left ($x0,$y0) and bottom right ($x1,$y1) using $colour. If optional argument
$fill
is true then the diamond is filled.In the current code a filled diamond uses a "polygon" item and an unfilled uses a "line" segments item. The line segments ensure interior points are not part of the diamond for
find("overlapping")
etc, the same as they're not for an unfilled ellipse or rectangle. Is that the best way? $image->load ()
$image->load ($filename)
-
Currently there's no file format to read a canvas.
$image->save ()
$image->save ($filename)
-
Save encapsulated postscript to
-file
, or with a$filename
argument set-file
then save to that.
ATTRIBUTES
-width
(integer)-height
(integer)-
Setting these changes the size of the image.
-tkcanvas
-
The underlying
Tk::Canvas
object. -file_format
(string orundef
)-
The file format as a string like "png" or "jpeg", or
undef
if unknown or never set.After
load
the-file_format
is the format read. Setting-file_format
can change the format for a subsequentsave
.There's no attempt to check or validate the
-file_format
value, since it's possible to add new formats to Tk::Canvas at run time. Expectsave()
to croak if the format is unknown.