| Brady Colton 2004-03-27, 12:27 am |
| Thanks, This will help alot, and is very apprecciated.
Brady
"Aric Bills" <aricb@u.wwashingtonn.edu> wrote in message news:<c3q38l$rkc$1@nntp6.u.washington.edu>...
> Hi Brady,
>
> Here's how I would tile a background bitmap in a canvas:
>
> 1. load the source image to be tiled into memory
> 2. create a target image and put it on the canvas (and lower it if anything
> else is already on the canvas)
> 3. use the copy subcommand of the target image to copy the source image (use
> the -to option to get tiling)
>
> Here's some sample code to do those things. Additionally, the code creates
> some bindings to the canvas to retile the images whenever the canvas gets a
> configure event (i.e. when it changes size) and to delete the images when
> the canvas is destroyed.
>
> The code assumes you've already created a canvas. To use the code, call
> initBackground with the canvas widget name and the path to the bitmap you
> want to tile.
>
> Regards,
> Aric
>
>
> proc initBackground {canvas bitmapFilename} {
>
> package require Img
>
> set sourceImage [image create photo -file $bitmapFilename]
> set tiledImage [image create photo]
>
> $canvas create image 0 0 \
> -anchor nw \
> -image $tiledImage \
> -tags {backgroundBitmap}
>
> $canvas lower backgroundBitmap
>
> bind $canvas <Configure> [list tile $canvas $sourceImage $tiledImage]
> bind $canvas <Destroy> [list image delete $sourceImage $tiledImage]
> tile $canvas $sourceImage $tiledImage
> }
>
> proc tile {canvas sourceImage tiledImage} {
>
> $tiledImage copy $sourceImage \
> -to 0 0 [winfo width $canvas] [winfo height $canvas]
> }
|