Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Dec 14, 2018 7:18 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: System.Pixel Workaround
PostPosted: Sun Dec 25, 2011 4:59 am 
Offline

Joined: Sun Mar 26, 2006 11:02 am
Posts: 85
System.Pixel is broken in Lion. Recently Joe Ranieri provided a workaround using Core Graphics routines, packaged conveniently in a Module downloadable from Feedback. As with everything CG-related, it's super-speedy and very light-weight, and, as shown in the routine below, it's possible to copy the screen directly into a Canvas without an intermediate Picture. Thanks, Joe!

NOTE: Cocoa only. For Carbon, see Joe's Module.
Sub PaintScreenshot(g As Graphics, dx As Integer, dy As Integer, dw As Integer, dh As Integer, sx As Integer, sy As Integer, sw As Integer, sh As Integer)
Dim cgi, cgc As Integer
Dim r As CGRect

Declare Function CGWindowListCreateImage Lib "ApplicationServices.framework" (screenBounds As CGRect, listOptions As UInt32, windowID As UInt32, imageOption As UInt32) As Integer
Declare Sub CGContextDrawImage Lib "ApplicationServices.framework" (context As Integer, rect As CGRect, image As Integer)
Declare Sub CFRelease Lib "CoreFoundation.framework" (obj As Integer)

Const kCGWindowListOptionOnScreenOnly = 1
Const kCGNullWindowID = 0
Const kCGWindowImageDefault = 0

r.origin.x = sx ' set source rect
r.origin.y = sy
r.rsize.width = sw
r.rsize.height = sh

cgi = CGWindowListCreateImage(r, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault) ' snap screen

if cgi <> 0 then

cgc = g.Handle(g.HandleTypeCGContextRef) ' get context of g

r.origin.x = dx ' set dest rect
r.origin.y = g.Height - dh - dy ' (0, 0) in g is top-left instead of CG's bottom-left
r.rsize.width = dw
r.rsize.height = dh

CGContextDrawImage cgc, r, cgi ' draw cgi into cgc using r as dest
CFRelease cgi

end if
End Sub

To make this work you'll need to define Structures:
CGPoint:
x as single
y as single

CGRect:
origin as CGPoint
rsize as CGSize

CGSize:
width as single
height as single
If you really, really need an individual pixel of the screen you can convert the CG image to a Picture and examine RGBSurface.Pixel(x, y).


Top
 Profile  
Reply with quote  
 Post subject: Re: System.Pixel Workaround
PostPosted: Sat Mar 10, 2012 3:11 am 
Offline

Joined: Tue Oct 13, 2009 4:21 am
Posts: 46
PSmith wrote:
For Carbon, see Joe's Module.


-How do I find it?

I found a thread in the feedback report (18933) and I found this at the bottom:
"Joe Ranieri - måndag 12 december 2011 @ 19:17
»» File(s) attached: screenshot.rbp
CGWindowListCreateImage and CGWindowListCreateImageFromArray are what you're after on OS X. Instead of grabbing the screen pixel by pixel, this gives you back a CGImage of the windows you're after (or a rectangle of the screen).
The attached example does exactly this."

But have no idea on how to grab the attachment? -It is not clickable in the feedback report.
I have searched for two hours now, but I am not able to find anything.

-Is this workaround about taking screenshots and examining it?
-If I need only one pixel, I have now to take a screenshot and examine it?


Top
 Profile  
Reply with quote  
 Post subject: Re: System.Pixel Workaround
PostPosted: Mon Mar 12, 2012 5:25 am 
Offline

Joined: Sun Mar 26, 2006 11:02 am
Posts: 85
There's a "View Attachments" icon at the bottom of the Feedback window. It looks disabled but it isn't really. :? Select "screenshot.rbp.zip" and choose "Save Attachment..." I agree, it would be nice if the "link" in the comments were hot....
Quote:
-Is this workaround about taking screenshots and examining it?
-If I need only one pixel, I have now to take a screenshot and examine it?
Yes, it's about taking screenshots using Core Graphics declares. And I suspect System.Pixel originally did it the same way: took a screenshot and returned one pixel!


Top
 Profile  
Reply with quote  
 Post subject: Re: System.Pixel Workaround
PostPosted: Thu May 10, 2012 4:53 pm 
Offline

Joined: Thu May 10, 2012 4:51 pm
Posts: 1
I was wondering if you had the link for Joe's code.


Top
 Profile  
Reply with quote  
 Post subject: Re: System.Pixel Workaround
PostPosted: Thu Dec 06, 2012 5:43 pm 
Offline

Joined: Mon Oct 09, 2006 9:05 am
Posts: 145
Does someone get the code above (PaintScreenshot) work? Or has someone a sample project that works ?

In a cocoa project, I setup a module with method PaintScreenshot and structures above. Before I call the method PaintScreenshot I generate the graphics like:
Dim g as Graphics
g=Window1.Canvas1.Graphics
g.ForeColor=RGB(255,0,0)
//g.FillRect (0,0,400,300)
g.DrawRect (0,0,400,300)

PaintScreenshot(g, 0, 0, 400, 300, 0, 0, 1200, 900)


I get the rect in the canvas but not the screenshot. What's wrong here?
Another question is, how can I draw it to the display(e.g. main display) and not in a canvas?

Thank you in advance.

_________________
Working system: Mac OS X 10.6.x
_________________________________
Note : I am not interested in any solutions that need custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group