• 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 15:49:19 -0500


You're retaining myCompositionRep too many times. It starts with retain 1 since it's an init.. initializer, then you explicitly retain it, then NSImage retains it when you add it. The same deal with NSImage: when you use an init.. initializer, the object is owned by you, meaning it's not in autorelease. You need to read the Cocoa memory management guide. Adding retains everywhere does seem to solve problems (IE, no crashes), but it causes very bad memory leaks.


I have no idea what you're trying to accomplish by adding the same rep to the same image multiple times (without removing the old representations no less), so I don't know how to help you. I think you need to read the NSImage documentation as to how it manages internal representations.

Why are you using an NSBitmapImageRep? You can just as easily draw directly into the NSImage with -lockFocus. If you're manipulating the raw pixel data of the bitmap image, I think you'll have to make a new NSImage each time you want to use the rep (because of NSImage caching - I could be wrong, though, it might propagate to the image).

- Dorian

On Jul 7, 2007, at 2:26 PM, Jeremy Rotsztain wrote:


Hello.

My imaging software continuously updates a NSImage object with the contents of a NSBitMapImageRepresentation.

I'm drawing into the image representation every frame, and adding the image representation to the NSImage again, but I'm unable to see the updated NSImage when I display it in a NSImageView or export it to disk using [ NSData writeToFile ].

Any advice on getting this to work would be greatly appreciated.

Jeremy



In my code, it looks something like this.

init:

NSImage *myComposition = [[[NSImage allocWithZone:[self zone]] initWithSize:compositionSize ] retain ];

// create img representation
NSBitmapImageRep *myCompositionRep = [[NSBitmapImageRep allocWithZone:[self zone]]
initWithBitmapDataPlanes: nil // Nil pointer tells the kit to allocate the pixel buffer for us.
pixelsWide: compositionSize.width
pixelsHigh: compositionSize.height
bitsPerSample: 8
samplesPerPixel: 4
hasAlpha: YES
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace // 0 = black, 1 = white in this color space.
bytesPerRow: 0 // Passing zero means "you figure it out."
bitsPerPixel: 32]; // This must agree with bitsPerSample and samplesPerPixel.



[ myCompositionRep retain ];

// add representation to main image
[ myComposition addRepresentation:myCompositionRep ];

drawing loop:

// draw into myCompositionRep

[ myComposition addRepresentation:myCompositionRep ];

_______________________________________________

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


References: 
 >Fwd: NSImage representations (From: Jeremy Rotsztain <email@hidden>)

  • Prev by Date: Re: 2nd Try: Access raw pixel data of a CIImage?
  • Next by Date: Re: 2nd Try: Access raw pixel data of a CIImage?
  • Previous by thread: Fwd: NSImage representations
  • Next by thread: Re: NSImage representations
  • Index(es):
    • Date
    • Thread