Bitmap(3pm)
π NAME π
Tk::Bitmap β images that display two colors, that's it, that's the whole vibe β¨
This is part of the User Contributed Perl Documentation bestie, we're in the perl/Tk corner of the internet π«Ά
β¨ SYNOPSIS β¨
$image = $widget->Bitmap?(name??,options?)
Like. that's literally it. that's the whole entry point π
π¦ DESCRIPTION π¦
okay so picture this: a bitmap is an image where every pixel is doing one of three things β it's showing one color, or it's showing the other color, or it's fully transparent. no in-between. no gradients. no "a little bit of both". just vibes and binary decisions, main character energy fr fr π
A bitmap image is defined by four things, and yes you need all of them:
- a background color
- a foreground color
- a bitmap called the source
- a bitmap called the mask
Both of those bitmaps specify 0/1 values for a rectangular array of pixels, and here's the rule β the two bitmaps must have the same dimensions. no cap, they gotta match, it's giving coordinated outfits πΈ
So how do the pixels decide? For pixels where the mask is zero, the image displays nothing at all, which is what gives you that transparent effect π«₯. For every other pixel, the image displays the foreground color if the source data is one, and the background color if the source data is zero. simple as that bestie π
π CREATING BITMAPS π
Bitmaps get created with $widget->Bitmap, and they support all of these options π
-background => colorβ sets a background color for the image, in any of the standard ways Tk accepts colors π. BUT β plot twist β if you set this option to an empty string, then the background pixels become transparent instead. The way it pulls this off is by using the source bitmap as the mask bitmap, and ignoring any-maskdataor-maskfileoptions you passed. iconic behaviour honestly π-data => stringβ the contents of the source bitmap, handed over as a string. That string must adhere to X11 bitmap format (think, like, the stuff generated by thebitmapprogram). And heads up: if you specify both-dataand-file, then-datatakes precedence π-file => nameβ name is the name of a file whose contents define the source bitmap. That file must adhere to X11 bitmap format (e.g., as generated by thebitmapprogram) π-foreground => colorβ sets a foreground color for the image, again in any of the standard ways Tk accepts colors π-maskdata => stringβ the contents of the mask as a string. It must adhere to X11 bitmap format (e.g., as generated by thebitmapprogram). And yup, same rule as before: if you specify both-maskdataand-maskfile,-maskdatawins π-maskfile => nameβ name is the name of a file whose contents define the mask. That file must adhere to X11 bitmap format (e.g., as generated by thebitmapprogram) π§
reminder bestie: the X11 bitmap format thing is not optional, it's a must. do not freestyle the format π
π IMAGE METHODS π
When a bitmap image gets created, Tk also spins up a brand new object for you β¨ and that object supports the configure and cget methods described over in Tk::options. Which means you can enquire about and modify all those options we just talked about. go poke at it, it's your object now π«Ά
π SEE ALSO π
Tk::Image Tk::Pixmap Tk::Photo
β KEYWORDS β
bitmap, image
okay that's the whole page bestie, go make some two-color icons and slay π β¨
signing off from the perl/Tk group chat β this doc ships with perl v5.40.1, dated 2025-04-13, and it's the manual page for Bitmap(3pm) ππ
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms