Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 749059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:23:29+00:00 2026-05-14T14:23:29+00:00

i’m porting an iphone app to Mac app,there i have to change all the

  • 0

i’m porting an iphone app to Mac app,there i have to change all the UIKit related class to AppKit.
if you can help me on this really appreciate. is this the best way to do below part..

Iphone App–>using UIKit

UIGraphicsPushContext(ctx);
[image drawInRect:rect];
UIGraphicsPopContext();

Mac Os–Using AppKit

[NSGraphicsContext saveGraphicsState];
NSGraphicsContext * nscg = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES];
[NSGraphicsContext setCurrentContext:nscg];
NSRect rect = NSMakeRect(offset.x * scale, offset.y * scale, scale * size.width, scale * size.height);
[NSGraphicsContext restoreGraphicsState];

[image drawInRect:rect fromRect:NSMakeRect( 0, 0, [image size].width, [image size].height )
        operation:NSCompositeClear
         fraction:1.0];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:23:29+00:00Added an answer on May 14, 2026 at 2:23 pm

    The docs and the docs are your friends; they’ll explain a lot of things that you’re misusing here.

    [NSGraphicsContext saveGraphicsState];
    NSGraphicsContext * nscg = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES];
    [NSGraphicsContext setCurrentContext:nscg];
    

    You save the graphics state in the current context, and then immediately create a new context and set it as current.

    NSRect rect = NSMakeRect(offset.x * scale, offset.y * scale, scale * size.width, scale * size.height);
    

    This is apparently all you gsaved for. Creating a rectangle is not affected by the gstate, since it isn’t a drawing operation (the rectangle is just a set of numbers; you’re not drawing a rectangle here).

    Furthermore, you should use the current transformation matrix for the scale.

    [NSGraphicsContext restoreGraphicsState];
    

    And then you grestore in the context you created, not the one you gsaved in.

    [Edit] Looking at this again a year and a half later, I think you misinterpreted the saveGraphicsState and restoreGraphicsState methods as a counterpart to UIGraphicsPushContext and UIGraphicsPopContext. They’re not; saveGraphicsState and restoreGraphicsState push and pop the graphics state of the current context. The current context is separately controlled (setCurrentContext:) and does not have a push/pop API. [/Edit]

    I’m assuming that you’re in a CALayer’s drawInContext: method? If this is in an NSView, then you already have a current context and don’t need to (and shouldn’t) create one.

    [image drawInRect:rect fromRect:NSMakeRect( 0, 0, [image size].width, [image size].height )
            operation:NSCompositeClear
             fraction:1.0];
    

    The NSCompositeClear operation clears the destination pixels, like the Eraser tool in your favorite paint program. It does not draw the image. You want the NSCompositeSourceOver operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I have a text area in my form which accepts all possible characters from
Thanks in advance for your help. I have a need within an application to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.