[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImage drawing in a NSCell



> I have subclassed NSCell to use it in a NSMatrix, I want to display an
> image in each cell and I want this image (from a grayscale TIFF file) to
> be scaled to the cell's size and eventually draw over it.  I wrote a
> drawInteriorWithFrame:inView: method, I can easily draw using
> NSBezierPaths but I can't figure out how to draw the NSImage.  For this
> purpose I tried many things including
> NSRect r;
> r.size=[[self image] size];
> [[self image] drawInRect:cellFrame fromRect:r operation: NSCompositeCopy
> fraction:1];
>
> appears, only what I draw using NSBezierPaths... I tried using
> fraction:0 or operation:NSCompositeSourceOver, still nothing, I tried
> other methods in NSImage such as compositeToPoint:cellFrame.origin and
> others (I some of them won't scale teh image but for now just getting
> something would be a start)... I still don't get any image drawn.  I
> know that my NSImage is fine because if I call [super
> drawInteriorWithFrame:cellFrame inView:controlView]; the image actually
> appears correctly.  I also tried locking focus on the view but it didn't
> change anything.

   Well, perhaps it's a cut-and-paste error into the e-mail you sent, 
but... I notice you're not setting r.origin to anything.  As a stack 
temporary, it's likely to have some random large value in it by default 
that will cause the source rect provided to be outside the bounds of the 
actual source image.  I believe clipping will then save you from a bad 
memory access crash, and will result in nothing being copied.
   If this error is not present in the actual code you're working with, 
then... I would suggest spending some quality time in gdb.  :->

Ben Haller
Stick Software