• 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: Help with pixellated NSTIFFRepresentation issues much appreciated
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with pixellated NSTIFFRepresentation issues much appreciated


  • Subject: Re: Help with pixellated NSTIFFRepresentation issues much appreciated
  • From: Robert Clair <email@hidden>
  • Date: Wed, 6 Oct 2004 16:58:29 -0400

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

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Help with pixellated NSTIFFRepresentation issues much appreciated
      • From: Keith Blount <email@hidden>
  • Prev by Date: Re: Selection and insertion point handling w/ NSTextAttachments
  • Next by Date: Re: Using outlets from NSView subclass
  • Previous by thread: Re: Setuid bit set, but not running as root
  • Next by thread: Re: Help with pixellated NSTIFFRepresentation issues much appreciated
  • Index(es):
    • Date
    • Thread