• 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: Image cache: Where is it and how do I refresh it?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Image cache: Where is it and how do I refresh it?


  • Subject: Re: Image cache: Where is it and how do I refresh it?
  • From: "Michael Ash" <email@hidden>
  • Date: Sun, 28 May 2006 13:58:04 -0400

On 5/27/06, Gregory Weston <email@hidden> wrote:
Ran into an unexpected problem last night while updating some pixel-
level manipulation to be Intel-friendly. Spent a while searching
Google and the list archives for ideas with no joy. Here's the
situation:

1) I've got an NSView subclass whose drawRect: (among other things)
draws part of an NSImage into (all of) itself, using
NSImage>>drawInRect:fromRect:operation:fraction:.

2) I create a data buffer and load it with pixel data. I construct an
NSBitmapImageRep using that buffer. I construct an NSImage and add
the rep.

My NSView comes up on-screen and draws itself exactly as I expect.
Then at some point the pixel buffer changes and setNeedsDisplay:YES
is sent to the view. And it does redraw itself. But it's still
showing the original image. I add some code before the
setNeedsDisplay to dump the NSImage as a TIFF and that saved file has
the updated image. NSImage>>representations returns an array with a
single entry, and it's the one I created.

Sending setCacheMode:NSImageCacheNever to the image doesn't help.

If I remove the imagerep from the image and add a new one created
from the same buffer it works.

The fact that the TIFF save works while a subsequent draw doesn't
suggests to me that the view or window is doing the caching and
recognizing that it's being asked to draw the same image but _not_
recognizing (understandably, I suppose) that the pixel data for the
imagerep in that image has changed. Can anyone confirm where my stale
cache is and suggest a way to refresh it?

I think there's two levels of caching going on. -setCacheMode: determines the caching behavior used by the individual image reps. But the caching you're seeing is done by NSImage itself, creating an NSCachedImageRep and then drawing from that. Although this does not explain why you only see one representation in the image (unless the cached rep is actually replacing the original).

I don't believe NSImage makes any guarantee that it will pick up
changes made to its contained image reps. My interpretation  of the
-setCacheMode: docs is that it exists solely to make memory/speed
tradeoffs

In any case, if all you need is drawing, you should be able to bypass
NSImage altogether and use NSImageRep's drawing facilities directly.
It doesn't offer a direct equivalent to the NSImage method you're
using, but you should be able to make it work. To draw part of the
image (rep) into all of your view, use -drawInRect: with a rect that
is suitably scaled, so that the visible portion includes the part of
the rep that you need.

Mike
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Image cache: Where is it and how do I refresh it? (From: Gregory Weston <email@hidden>)

  • Prev by Date: Re: 2Qs
  • Next by Date: Custom Field Editor for NSTableView with bindings
  • Previous by thread: Image cache: Where is it and how do I refresh it?
  • Next by thread: Re: Image cache: Where is it and how do I refresh it?
  • Index(es):
    • Date
    • Thread