I have an image that displays properly when it is displayed - and the mask is correct (it’s a PNG with Alpha). For a listbox where I want to place a count bug onto the image, I use the following code:
Dim bigP As New Picture(TapeImage26x26.Width, TapeImage26x26.Height, 32)
Dim bigM As New Picture(TapeImage26x26.Width, TapeImage26x26.Height, 32)
Dim bigMG As Graphics = bigM.Graphics
bigP.Graphics.DrawPicture TapeImage26x26, 0, 0
bigMG.DrawPicture(TapeImage26x26, 0, 0)
bigP.Mask = bigM
Dim slen As Double = bigP.Graphics.StringWidth(Str(MyTapeSetRecords(x).trVolumeCount))
Dim p As New Picture(sLen + 2, 14, 32)
Dim pG As Graphics = p.Graphics
pG.TextFont = "Helvetica"
pG.TextSize = 10
pg.Bold = True
pG.ForeColor = &c6278E300
pG.FillRoundRect(0,0,sLen + 2, 14, 7, 7)
pG.ForeColor = &cFFFFFF00
pG.DrawString(Str(MyTapeSetRecords(x).trVolumeCount), 1, 9)
bigP.Graphics.DrawPicture(p, TapeImage26x26.Width - (slen + 2), TapeImage26x26.Height - 14)
Unfortunately, the result of applying the mask to the new bigP picture looks as if the mask wasn’t fully black (the lighter versions here):
Do any of you see what I’m doing incorrectly in the code to cause that?
I can’t draw the badge onto the original because I reuse the original many times. If I just create the new picture and draw the badge, the mask is discarded and the image is antialiased white around the picture.
I still don’t think you should need to be mucking with masks. Can I ask if this is happening in a Listbox CellBackgroundPaint event? Or is this a neat way to cache the image to avoid that much drawing? I would take the tape image and draw the badge on top in a new image (which you shouldn’t need to mask).
Color me intrigued, this could be a fun little project to solve.
Feel free to shoot me an email or PM if you want to send a lot of details.
this is the method I use for all my “badged” controls
I think somewhere on this forum I posted a link to a custom “iOS like” tabbar for Xojo (desktop) which does this
It returns a Picture so you can shove it into RowPicture if you want. It’s likely not HiDPI friendly and might require some tweaking. The positioning of the digit in the badge background isn’t absolutely perfect, but again can be tweaked to suit
Because I know I clean out my Dropbox frequently here’s the badge method code for future reference:
[code]Public Function MakeBadge(sLabel as String) as Picture
dim pTemp as new Picture(picTape.Width, picTape.Height)
dim g as Graphics = pTemp.Graphics
g.DrawPicture(picTape, 0, 0)
g.TextFont = “Helvetica”
g.Bold = True
g.TextSize = 24
const kPadding = 5
dim iBadgeTextLength as Integer = g.StringWidth(sLabel)
dim iBadgeTextHeight as Integer = g.StringHeight(sLabel, 9001)
dim iBadgePosX as Integer = pTemp.Width - (kPadding * 3) - iBadgeTextLength
dim iBadgePosY as Integer = pTemp.Height - (kPadding * 3) - iBadgeTextHeight