locked
How can I use CoreGraphics CGDisplayScreenSize? RRS feed

  • Question

  • User56148 posted

    I am trying to convert this Objective-C code into Xamarin. The CoreGraphics binding does not seem to expose the CGDisplayScreenSize method. Is there a way to use this, or another way to get the screen size?

    ` NSDictionary *description = self.screen.deviceDescription;

    unsigned int screenNumber = [description[@"NSScreenNumber"] unsignedIntValue]; CGSize physicalSize = CGDisplayScreenSize(screenNumber);

    CGSize pixelSize = [description[NSDeviceSize] sizeValue]; CGFloat dpi = pixelSize.width/physicalSize.width*25.4f; `

    Wednesday, November 4, 2015 2:42 AM

Answers

  • User35201 posted

    We currently don't have a binding for that API. Here is a related filed bug:

    https://bugzilla.xamarin.com/show_bug.cgi?id=25723

    But this manual binding appears to work for me as a work around:

        [System.Runtime.InteropServices.DllImport ("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")]
        static extern CoreGraphics.CGSize CGDisplayScreenSize (uint display);
    
    
            System.Console.WriteLine (CGDisplayScreenSize (0));
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 4, 2015 2:22 PM

All replies

  • User35201 posted

    We currently don't have a binding for that API. Here is a related filed bug:

    https://bugzilla.xamarin.com/show_bug.cgi?id=25723

    But this manual binding appears to work for me as a work around:

        [System.Runtime.InteropServices.DllImport ("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")]
        static extern CoreGraphics.CGSize CGDisplayScreenSize (uint display);
    
    
            System.Console.WriteLine (CGDisplayScreenSize (0));
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 4, 2015 2:22 PM
  • User56148 posted

    Great thank you, I thought I would have to bind it myself but I'm still trying to learn how to do that. Thanks!

    Wednesday, November 4, 2015 2:26 PM
  • User35201 posted

    The new user documentation here:

    http://developer.xamarin.com/guides/mac/gettingstarted/hello,mac/

    is getting pretty good. It might be worth checking out.

    The sections on binding are at:

    http://developer.xamarin.com/guides/mac/advanced_topics/binding-troubleshooting/

    with these sections being useful to read for background:

    http://developer.xamarin.com/guides/mac/advancedtopics/internals/ http://developer.xamarin.com/guides/mac/applicationfundamentals/patterns/ http://developer.xamarin.com/guides/mac/application_fundamentals/mac-apis/

    Wednesday, November 4, 2015 2:33 PM