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

NSImage drawing in a NSCell



Hi everyone,
Once again I am stuck on something...

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.

Am I missing something? I tought about using an NSImageRep from the 
image but I understand NSImage does this and even caches them, which 
seems more practical for me.

Anyone as an idea of what I might be doing wrong.. any gotchas I should 
know about?

Oh... one other thing, maybe I should dedicate anothe post to this one 
but here it goes:
Can I get an image representation using a specified bits per pixel, and 
samples by pixel ? In this case I'd like to turn RGB or RGBA images to 
256 grayscale images (a char array)... i could write code that does it 
but I tought it could be provided by Cocoa.

Yan Laporte
LASIM, Université de Sherbrooke
GDAC, UQAM
ylaporte@xxxxxxx