Help with pixellated NSTIFFRepresentation issues much appreciated
Help with pixellated NSTIFFRepresentation issues much appreciated
- Subject: Help with pixellated NSTIFFRepresentation issues much appreciated
- From: Keith Blount <email@hidden>
- Date: Wed, 6 Oct 2004 12:09:13 -0700 (PDT)
Hello,
I am currently trying to enable the copying and
pasting of an image between a text view and an image
view. Thanks to some help here I now have it working
reasonably - I am able to drag the image from the text
view into the image view and can easily drag from the
image view into the text view. In both cases I am
copying the image across as data, using
TIFFRepresentation to encode the image as tiff data
and putting this on the dragging pasteboard.
However, I have the problem that when I copy the image
out of the image view into the text view (or anywhere
else for that matter) and then copy it back from the
text view into the image view, the image becomes
blocky and pixellated when scaled up (the image view
has a scaling feature), although everything was smooth
before it was copied out and pasted back in. This is
no good, as one of the ideas behind the image view is
that the user can drag pictures there from the text
view, rescale them, and then drop them back into the
text view.
I have narrowed this down to the way I am copying the
image onto the pasteboard from the image view. This is
how I am currently doing it:
- (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 set
Data:[dropImage TIFFRepresentation]
forType:NSTIFFPboardType];
[dropImage release];
}
}
Note that this seems a long winded way of doing it
anyway. 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. I have no idea
why, as the zoom function I have created for the image
view sets the image view's image using a properly
scaled image, like this:
NSImage *scaledImage = [image copy];
[scaledImage setScalesWhenResized:YES];
NSSize imageSize = [scaledImage size];
[scaledImage setSize:NSMakeSize(imageSize.width*zoom,
imageSize.height*zoom)];
[imageView setZoomedImage:scaledImage];
[scaledImage release];
// (Note that image is an NSImage instance variable of
the same class
// of which the image view - imageView - is also an
instance variable.)
To reiterate, my problem is that if I paste an image
copied FROM the image view back TO the image view, it
loses quality when rescaled, becoming completely
pixellated, whereas before it was copied out it scaled
up very smoothly without becoming blockly. I have
searched the archives and found some posts about image
scaling, but nothing has worked (including changing
the NSImage to an NSBitmapRepresentation and setting
the antialiasing etc of the graphics context).
If anybody could give me some suggestions or hints on
how I might improve these methods so that the tiff
data copied from the scaled image view is of the same
quality as the original unscaled image, I would be
really grateful.
Many thanks in advance for any help,
Keith
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
_______________________________________________
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