Does MBS Screenshot have Alpha?

I have some code that works great for fading a png file, but when I try to take a screen shot with MBSscreenshot rectangle and do a copymask, it says nil object. I have read that mac screenshots do have alpha, so why is this saying the alpha channel is nil?

for a whole screenshot, alpha channel would be a waste.

Alpha channel makes only sense for portions like a window only.


You may want to try command line ScreenCapture. Since it is part of OSX, it may provide a better rendition.

Thanks guys. I am trying to learn about manipulating graphics to create screen effects and overlays. The current problem is:

I have a group of windows put together that are on another vendors software program slid together into a rectangle. I want to screen shot a single rectangle over those grouped windows which will appear as a single rectangle with various components inside. After I have the screen shot, I will place the screenshot on top of their windows, then make their windows hide but my screenshot will remain, and it will appear as though their windows are still showing. Their windows on immediately show or hide. My window will be a trick that makes their windows fade out. I have code that can fade a png in resources if the png was created in photoshop and saved into resources. However when I use the same code, only substituting the fresh MSBscreenshot, I get nil object

dim surf_m as RGBSurface = m.RGBSurface /// error nil object exception

This suggests that the RGBsurface was never created, but it works perfectly on the png file.

I like the idea of CGwindows but that looks like it is a learning curve to tackle for the weekend. For now, I would still like to solve why the screenshot is failing in RGBsurface. If this is not workable, then I will test the CGwindows to see if it will provide a way to get a window and fade it. But the goal is to learn a lot about manipulating overlays.

Dim p as picture
p = screenshotRectMBS(720, 26, 897, 435) / /select the grouped windows from the other app
//p = target_1x // This is a png in resources this works fine

dim AlphaValue as integer = 200 ///test setting
// Get the mask
dim p_masked as Picture
if AlphaValue > 0 then
p_masked = ScaleMask(p, AlphaValue)
p_masked = p
end if
winFakeSendBox.backdrop = p_masked

Private Function ScaleMask(p as Picture, val as byte) As Picture
// The alpha channel is the translucency of the color represented as an integer
// between 0 (opaque) and 255 (transparent).

// Get the mask
dim m as Picture = p.CopyMask

// Create transformation map
dim map(255) as integer
for i as integer = 0 to 255
dim delta as double = (255 - i) * val / 255
map(i) = min(255, i + delta)

// Apply transformation map to the Mask
dim surf_m as RGBSurface = m.RGBSurface /// < < < < < < FAILS <<<<<<<<<

// Clone the orignal picture
dim p_new as new Picture (p.Width, p.Height)
p_new.Graphics.DrawPicture(p, 0, 0)

'apply the new mask

return p_new
End Function[/code]

The picture from screenshotRectMBS is opaque and has no mask. So copying it will not work.

dim p as Picture = CGWindowMBS.CreateWindowListImage(0, 0 ,0, 0, CGWindowMBS.kCGWindowListOptionIncludingWindow, CGWindowMBS.GetWindowID(Window1)) Backdrop = p

like this you get screenshot of a window.

Thanks, I am assuming that if it is still a screenshot that it will still not work for fading? If so, then maybe I can screenshot the area, then convert to jpg into a mblock, then convert the jpg back to picture.

I will test out the CGwindows this weekend. I am on Yosemite.

I think we have an example for fading with overlayMBS window.

[code]Function ConvertToAlphaPicture(input As Picture) As Picture
If input.HasAlphaChannel Then Return input

Dim result As New Picture(input.Width, input.Height)
result.Graphics.DrawPicture(input, 0, 0)
Return result
End Function[/code]