An important side note (thanks to Johan Lindstrom) is that the "$bitmap" is only valid in its current scope, ie, if you make this a function and return, then the $bitmap is no longer valid (bug in GUI), so you'll need to make it global. I tried this numerous ways an got a lot of headaches until this was "uncovered".