I’m getting icons for extensions and then use this image as drag image. The icon image has an alpha channel but the drag image needs a picture with a mask (bug?). How do I convert an alpha channel to a mask?
First part for getting an icon for an extension:
[code] const extension = “gz”
const ScaleFactor = 1
const size = 256
dim theIcon as IconMBS = new IconMBS("", “”, extension, “”)
dim pic as new Picture(size * ScaleFactor, size * ScaleFactor)
dim thePictureContext as CGBitmapContextMBS = CGBitmapContextMBS.CreateWithPicture(pic)
const DrawNormal = 0
const DrawNoImage = 2
const DrawNoMask = 4
const DrawSelected = &h8000
if theIcon = nil or thePictureContext = nil then
'Return nil
end if
thePictureContext.ClearRect CGRectMBS.Make(0, 0, size * ScaleFactor, size * ScaleFactor)
theIcon.DrawIconCGContext(thePictureContext.Handle, 0, 0, size * ScaleFactor, size * ScaleFactor, 0, 0, DrawNormal, &c000000)
thePictureContext.Flush[/code]
If I use the following code for converting the alpha channel to a mask:
Dim surf As RGBSurface = pic.RGBSurface
dim MaskPicture as new Picture(pic.Width, pic.Height)
dim masksurf as RGBSurface = MaskPicture.RGBSurface
Dim lastX As Integer = pic.Width - 1
Dim lastY As Integer = pic.Height - 1
For y As Integer = 0 To lastY
For x As Integer = 0 To lastX
dim i as Integer = surf.Pixel(x, y).Alpha
masksurf.Pixel(x, y) = RGB(i, i, i)
Next
Next
then I get a white ring on black. What is wrong here?
Xojo 2016r11. Mac OS 10.11.4.