• 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: optimizing background image drawing with -drawRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: optimizing background image drawing with -drawRect


  • Subject: Re: optimizing background image drawing with -drawRect
  • From: "I. Savant" <email@hidden>
  • Date: Mon, 2 Apr 2007 14:31:21 -0400

On 4/2/07, Artemiy Pavlov <email@hidden> wrote:
My guess is I should load and scale the image once, and use -drawRect
to only do drawAtPoint. But the problem is I cannot move this part of
the code outside -drawRect, I get "error: initializer element is not
constant" for lines with NSString, NSImage, etc.

You guessed correctly - you should cache the image.

 I've actually never encountered the error you've mentioned. I guess
it depends how you're trying to "move the code outside" -drawRect: ...
I'd do it this way:

 In your interface, declare an image:

NSImage * cachedImage;

 Then declare a method to get the image:

- (NSImage *)cachedImage;

 In your implementation:

- (NSImage *)cachedImage
{
 if (!cachedImage)
   cachedImage = ...; // get/assign image here.

 return cachedImage;
}

 In your -drawRect: method, don't use the cachedImage pointer
directly (like [cachedImage someMessage]) but rather always get it via
the method above ([[self cachedImage] someMessage]... that way, the
image is cached the first time it's called and the cache is used from
then on.

 Hope this helps.

--
I.S.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: optimizing background image drawing with -drawRect
      • From: "I. Savant" <email@hidden>
References: 
 >optimizing background image drawing with -drawRect (From: Artemiy Pavlov <email@hidden>)

  • Prev by Date: Re: optimizing background image drawing with -drawRect
  • Next by Date: Re: error displaying @count via bindings
  • Previous by thread: Re: optimizing background image drawing with -drawRect
  • Next by thread: Re: optimizing background image drawing with -drawRect
  • Index(es):
    • Date
    • Thread