2011-03-28 18 views
6

मैं कैमटविस्ट 'डेस्कटॉप +' सुविधा जैसी खिड़की की सामग्री को पकड़ने का एक तरीका ढूंढ रहा हूं। यह पृष्ठभूमि में होने पर भी, किसी भी खिड़की को पकड़ सकता है।ओएसएक्स में एनएसविंडो के पिक्सेल बफर तक कैसे पहुंचे?

ऐप्पल का ओपनजीएलस्क्रीन कैप्चर नमूना दिखाता है कि मुख्य स्क्रीन से कैसे कैप्चर किया जाए लेकिन छिपी सतहों से नहीं।

कोई विचार कैसे कैमविस्ट को एनएसविंडो के पिक्सेल बफर तक पहुंच प्राप्त होती है?

उत्तर

5

AFAIK, सरकारी एपीआई CoreGraphics के हिस्से के रूप CGWindow.h में पाया जा सकता:

/* Create an image containing a composite of the specified set of windows 
    contained within a rectangular area. The set of windows is specified 
    using options from `CGWindowListOption', along with an optional 
    additional window ID. 

    The windows list options are: 

    --- kCGWindowListOptionAll, kCGWindowListOptionOnScreenOnly: Use all 
    on-screen windows in this user session to construct the image. The 
    parameter `windowID' should be `kCGNullWindowID'. 

    --- kCGWindowListOptionOnScreenAboveWindow: Use all on-screen windows in 
    this user session above the window specified by `windowID', ordered from 
    front to back, to construct the image. To include the window specified by 
    `windowID', add the flag `kCGWindowListOptionIncludingWindow'. 

    --- kCGWindowListOptionOnScreenBelowWindow: Use all on-screen windows in 
    this user session below the window specified by `windowID', ordered from 
    front to back, to construct the image. To include the window specified by 
    `windowID', add the flag `kCGWindowListOptionIncludingWindow'. 

    --- kCGWindowListOptionIncludingWindow: Use only the window specified by 
    `windowID' to construct the image. 

    The parameter `screenBounds' specifies the rectangle in screen space 
    (origin at the upper-left; y-value increasing downward). Setting 
    `screenBounds' to `CGRectInfinite' will include all the windows on the 
    entire desktop. Setting `screenBounds' to `CGRectNull' will use the 
    bounding box of the specified windows as the screen space rectangle. 

तोड़

/* The parameter `imageOptions' allows you to specify whether the window 
    frame ornamentation, such as a shadow or similar effect, should be 
    included or excluded in the bounds calculation when `CGRectNull' is 
    specified for the window bounds. 

    If no windows meet the specified criteria, or the windows can't be read, 
    then a transparent black image will be returned. 

    Any on-screen window with sharing type `kCGWindowSharingNone' will not 
    be included in the image. 

    This function returns NULL if the caller is not running within a Quartz 
    GUI session or the window server is disabled. */ 

CG_EXTERN CGImageRef CGWindowListCreateImage(CGRect screenBounds, 
    CGWindowListOption listOption, CGWindowID windowID, 
    CGWindowImageOption imageOption) 
    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA); 

/* Create an image containing a composite of the specified set of windows 
    contained within a rectangular area à la `CGWindowListCreateImage'. The 
    set of windows is specified by `windowArray', an array of window IDs. */ 

CG_EXTERN CGImageRef CGWindowListCreateImageFromArray(CGRect screenBounds, 
    CFArrayRef windowArray, CGWindowImageOption imageOption) 
    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA); 

क्षमा करें, एप्पल साइट पर प्रलेखन के लिए एक लिंक नहीं मिल सका। हालांकि, उनके पास Son of Grab में नमूना कोड प्रतीत होता है।

+0

शानदार! ग्रैब नमूना का बेटा वही करता है जो मैं खोज रहा था। आप अपने निकनाम के योग्य हैं :-) – Frans

4

AFAIK आप आधिकारिक API का उपयोग करके ऐसा नहीं कर सकते हैं। बेशक यह संभव है, अन्यथा ऐप्पल अन्यथा एक्सपोज़ को कैसे कार्यान्वित करेगा? Here you can find a header कि लोगों ने रिवर्स इंजीनियरिंग ऐप्पल के कोड द्वारा बनाया है; इसे अपने जोखिम पर उपयोग करें (एक निजी एपीआई होने के नाते, इनमें से कोई भी कॉल किसी भी समय और किसी भी अधिसूचना के बिना ऐप्पल से किसी भी रिलीज के साथ बदल सकती है) और उम्मीद नहीं है कि ऐप्पल आपको अपने ऐप स्टोर में जाने देगा, अगर आप इसका इस्तेमाल कर रहे हैं :-) जैसा कि आप देख सकते हैं, आप सभी एपीआई (छुपे हुए लोगों सहित) की एक सूची प्राप्त करने के लिए इस एपीआई का उपयोग कर सकते हैं और आप उन्हें भी कुशल बना सकते हैं; यद्यपि आपको वास्तव में क्या करने की अनुमति है, वह आपके ऐप विशेषाधिकारों पर निर्भर हो सकता है। And here's code जो दिखाता है कि आप अपनी पसंदीदा एपीआई का उपयोग कैसे कर सकते हैं, किसी भी विंडो की सामग्री को कैप्चर करने के लिए। कृपया ध्यान दें कि कोड ओएस संस्करण के आधार पर अलग-अलग काम करता है, यह एक तरीका है कि इसे पूर्व -10.5 कैसे करें और इसे 10.5 के बाद कैसे करें, इसलिए यदि आप पुराने सिस्टम को लक्षित कर रहे हैं, तो सुनिश्चित करें कि आप दोनों तरीकों को भी लागू करते हैं। वास्तव में छवि प्राप्त करने के लिए उपयोग की जाने वाली अंतिम एपीआई कॉल निजी, बीटीडब्लू नहीं हैं, वे आधिकारिक एसडीके हेडर में पाए जाते हैं, केवल उसी तरीके से आपको एक विंडो के संदर्भ में कैसे मिलता है जो आपकी वर्तमान प्रक्रिया से संबंधित नहीं है।

अद्यतन: विंडो सर्वर से विंडोआईडी की प्रतिलिपि बनाने के लिए 10.5 से महत्वपूर्ण कार्य को ऐप्पल द्वारा सार्वजनिक किया गया है; इसलिए यह अब निजी एपीआई नहीं है। हालांकि, 10.5 से पहले उन विंडोआईडी को पुनर्प्राप्त करना पहले से ही संभव था, लेकिन उस समय हेडर सार्वजनिक नहीं हुआ है और फिर भी उलटा इंजीनियर इंजीनियर में पाए गए सभी कार्यों को सार्वजनिक नहीं किया गया है, फिर भी।

संबंधित मुद्दे