I have a very similar setup. I tried the following.

NSBundle *bundle = [NSBundle mainBundle];
NSData *data = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"AAScreenShot" ofType:@"jpg"]];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:data];
NSGraphicsContext *context = [NSGraphicsContext 
graphicsContextWithBitmapImageRep:imageRep];
printf("Graphics Context %p\n", context);

Execute the above code and I get a graphics context when the window is in the 
high resolution display. Move the window to the secondary normal resolution 
display, execute the code, and I get another graphics context. You must be 
doing something wrong.

Normally a graphics context is valid for a given display. When the window moves 
from one display to another your app needs to detect this a pull another 
context.

https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_contexts/opengl_contexts.html

"A renderer change can occur when the user drags a window from one display to 
another or when a display is attached or removed.”

This might not be true with an offscreen context which might remain valid 
regardless of the display.

--Richard Charles


> On Mar 3, 2020, at 11:19 PM, Sravan Kumar Lakkimsetti via Cocoa-dev 
> <cocoa-dev@lists.apple.com> wrote:
> 
> Hi,
> 
> In our product we use
> https://developer.apple.com/documentation/appkit/nsgraphicscontext/1529827-graphicscontextwithbitmapimagere?language=objc
> to create Graphics Context for drawing on top of image.
> 
> This particular API returns null in some cases. One particular case is
> troubling us. Would like to know why this happens and how to resolve.
> 
> Here is the problem.
> There are two monitors attached to Mac. Main display is retina display and
> secondary display is non-retina display. The application is moved from main
> display(retina display) to secondary display(non-retina display). In this
> case our application redraws the GUI(to use higher resolution images) In
> this process we are creating graphics context using the above api. This api
> returns null if the main display is retina and secondary display is
> non-retina.
> 
> It would be helpful if anyone can suggest on how to identify why this api
> returns null
> 
> Thanks
> Sravan
> 
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to