• 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: NSImage representations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage representations


  • Subject: Re: NSImage representations
  • From: Dorian Johnson <email@hidden>
  • Date: Sat, 7 Jul 2007 16:18:11 -0500

You can create an NSImage, then do [img lockFocus], draw to it, then [img unlockFocus]. You can then do any sort of drawing to it. You'll want to stick with your current method if you want to set pixels directly for whatever reason.

If you retain an object to many times then don't need it any more, it won't get deallocated, so that memory will sit around without any chance for anything to touch it. This will cause your program to use all sorts of memory. Basically, any object that is acquired with [[Obj alloc] init..] or [obj copy..] has a retain count of one and you need to explicitly release it (or add to autorelease pool). ANY other object is generally assumed to be autoreleased (ie, [NSDictionary dictionary]), so you need to retain it if you're going to need it later (any time after that run loop cycle, that is). The NSImage documentation says "Any representation added by this method is retained by the receiver. Image representations cannot be shared among multiple NSImage objects." under -[NSImage addRepresentation].

setPixel is alright for some things, but it is *far* quicker to use - [NSBitmapImageRep bitmapData] and modify it directly. Just keep that in mind if you have a situation where you're working with entire images or otherwise are manipulating many pixels.

Just keep your image rep on hand, and every time you change it, create a new NSImage and add the rep. Creating a new image with [[NSImage alloc] initWithSize] then adding the representation is quite quick, because NSImage shouldn't create a blank pixel buffer unless it's needed (in this case, it isn't).

- Dorian

On Jul 7, 2007, at 3:59 PM, Jeremy Rotsztain wrote:


Hi Dorian,

Thanks for your response.

I retained myCompositionRep because I wanted to keep drawing to it (it's declared as a global variable in its class).
I was not aware of the fact that it's also retained by NSImage when I add it. I've read the Cocoa memory management guide ... but are there any documents that discuss memory usage regarding imaging? What happens when you retain an object too many times?


I'm using [ NSBitmapImageRep setPixel] to do the drawing, not raw pixel data. It's probably more optimal to do that method, but I haven't had a chance to look into that just yet.

Ah, would somebody usually turn off caching in that case? I think I saw something about caching in the NSImage documentation. I'll take a look.

Thanks,

Jeremy
_______________________________________________

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: NSImage representations
      • From: Jeremy Rotsztain <email@hidden>
References: 
 >Fwd: NSImage representations (From: Jeremy Rotsztain <email@hidden>)
 >Re: NSImage representations (From: Dorian Johnson <email@hidden>)

  • Prev by Date: Re: 2nd Try: Access raw pixel data of a CIImage?
  • Next by Date: Core Data + NSOutlineView + Sorting without NSTreeController
  • Previous by thread: Re: NSImage representations
  • Next by thread: Re: NSImage representations
  • Index(es):
    • Date
    • Thread