• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: bad behavior from unlockFocus on 10.6
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bad behavior from unlockFocus on 10.6


  • Subject: Re: bad behavior from unlockFocus on 10.6
  • From: Ken Ferry <email@hidden>
  • Date: Thu, 3 Sep 2009 09:50:34 -0700

Hi Bob,
> This all worked fine until 10.6. The original NSImage object was left
unmolested.

Nope. :-)  Clearly you're seeing behavior change somewhere, but this
attribution is not correct.

-[NSImage lockFocus] is a commonly misunderstood method.  It is and always
has been lossy.

Lock/unlock focus prior to 10.6 does this:

(1) Gets an offscreen window.
(2) Draws the image in the window.
(3) Sets up the current NSGraphicsContext such that further drawing is
directed to that window, restoring the original state in unlockFocus.
(4) *Replaces* the original representations of the image with the drawing
from the window.

In 10.6, it's similar, but there's no actual window.  It's just a buffer of
memory.

For more on the 10.6 changes to NSImage and company, see <
http://developer.apple.com/mac/library/releasenotes/Cocoa/AppKit.html>.

-Ken

On Thu, Sep 3, 2009 at 6:50 AM, Robert Clair <email@hidden> wrote:

>
> I have this piece of code in my drawing program:
>
>
>  [image lockFocus];
>
>  NSBitmapImageRep* bitmapRep =
>      [[NSBitmapImageRep alloc] initWithFocusedViewRect:
>              NSMakeRect( 0.0, 0.0, width, height) ];
>
>  [image unlockFocus];
>
> image is an NSImage with a single representation, either an
> NSBitmapImageRep containing a high resolution bitmap or an NSPDFImageRep.
> The pixels from the bitmapRep created here are thresholded and used to make
> a low resolution mask  that is held separately for use in picking.
>
> This all worked fine until 10.6. The original NSImage object was left
> unmolested. But now when this code is executed, -unlockFocus  replaces the
> original representation held by the NSImage object with an
> NSCGImageSnapshotRep. There is no documentation that I can find on a
> NSCGImageSnapshotRep, but it's a bitmap.  (I assume it's a screen res bitmap
> object backed by a CGImage). This causes data loss with the program. If, for
> example, a user opens a file with a pdf object in it to continue working on
> it , and then saves the file, all the vector information is lost in any pdf
> objects is lost.
>
> I understand that a pdf has to be rasterized for this to work. But since I
> didn't draw anything on the NSImage, I really expect this code to discard
> the temporary rasterized version when it is done and leave my original
> object unchanged.
>
> The quick fix is easy, just save the original representation and then
> restore it. But, is this a bug or is there some point to this?
>
> Bob Clair
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: bad behavior from unlockFocus on 10.6
      • From: Robert Clair <email@hidden>
References: 
 >bad behavior from unlockFocus on 10.6 (From: Robert Clair <email@hidden>)

  • Prev by Date: change in launch services binding behavior?
  • Next by Date: Re: iPhone-detecting call event...
  • Previous by thread: Re: bad behavior from unlockFocus on 10.6
  • Next by thread: Re: bad behavior from unlockFocus on 10.6
  • Index(es):
    • Date
    • Thread