Skip navigation.
 
mlRe: Help with pixellated NSTIFFRepresentation issues much appreciated
FROM : Robert Clair
DATE : Wed Oct 06 22:58:29 2004

> I thought I would just be able to set the data
> using [[self image] TIFFRepresentation], but this does
> not work. If I do this, the image is sometimes scaled
> properly, and other times not at all.



"not at all" means "not scaled" or "scaled but low res" ?
"Sometimes" means random results for the *same* image
(starting from scratch) or random results for different images ?

Anyway...

> - (void)pasteboard:(NSPasteboard *)sender
> provideDataForType:(NSString *)type
> {
>     if ( ([type isEqualToString:NSTIFFPboardType]) &&
> ([[sender name] isEqualToString:NSDragPboard]) )
>     {
>         NSRect imageBounds;
>         NSSize s = [[self image] size];
>         NSImage *dropImage = [[NSImage alloc]
> initWithSize:s];
>         imageBounds.origin = NSMakePoint(0,0);
>         imageBounds.size = s;
>         
>         // Draw the image
>         
>         [dropImage lockFocus];
>         //[[NSGraphicsContext currentContext]
> setImageInterpolation:NSImageInterpolationNone];
>         //[[NSGraphicsContext currentContext]
> setShouldAntialias:NO];
>         [[self image] drawInRect:imageBounds
>                         fromRect:imageBounds
>                       operation:NSCompositeCopy
>                         fraction:1.0];
>         [dropImage unlockFocus];
>         
>         [sender setData:[dropImage TIFFRepresentation]
> forType:NSTIFFPboardType];
>         [dropImage release];
>     }
> }
>


This isn't going to do what you want. (But you knew that :-) ).
As has been noted before, NSImage is really a container of sorts
for 1 or more NSImageRep's. It does strange, wonderful and
ill-documented
things, sometimes behind your back.

NSSize s = [myImage size];

means that the image will render at s.width x s.height in the current
coordinate system.
This size is *NOT*  the number of pixels wide by the number of pixels
high of your
actual bitmap data (if indeed you have any bitmap data at all - the
image could be a pdf or
an eps - but lets assume you really have a raster.) I you have a bitmap
that is scaling up nicely
using NSImage you must have an NSBitmapImageRep with a lot lot more
than s.width pixels
across - which is down sampled when you render it at size s.

In the code above, when you draw image into dropImage you are creating
an image with a
single NSCachedImageRep - an offscreen window - that has size s and is
s.width pixels wide and
s.height pixels wide: it contains the down sampled raster. You've lost
all the headroom - the extra
pixels that allowed you to scale the image.

Stepping things in the debugger and doing

po image

for the various images will give you the size of the image, its various
reps and their sizes and pixel sizes.
Often very enlightening.


Bob Clair

Related mailsAuthorDate
mlRe: Help with pixellated NSTIFFRepresentation issues much appreciated Robert Clair Oct 6, 22:58
mlRe: Help with pixellated NSTIFFRepresentation issues much appreciated Keith Blount Oct 8, 13:41
mlRe: Help with pixellated NSTIFFRepresentation issues much appreciated Robert Clair Oct 8, 16:58
mlRe: Help with pixellated NSTIFFRepresentation issues much appreciated Keith Blount Oct 12, 21:39
mlRe: Help with pixellated NSTIFFRepresentation issues much appreciated Aaron Fothergill Oct 12, 21:46
mlRe: Help with pixellated NSTIFFRepresentation issues much appreciated Robert Clair Oct 13, 16:34