Re: Help with pixellated NSTIFFRepresentation issues much appreciated
Re: Help with pixellated NSTIFFRepresentation issues much appreciated
- Subject: Re: Help with pixellated NSTIFFRepresentation issues much appreciated
- From: Keith Blount <email@hidden>
- Date: Fri, 8 Oct 2004 04:41:08 -0700 (PDT)
Many thanks for your reply.
>
"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 ?
Sorry for my lack of clarity. Basically, if I just use
[self image] to create the TIFFRepresentation, the
results seem random in that - for any image I place
into the image view - when dragged to the text view
the image may be completely unscaled, or it may be
scaled correctly, or it may be scaled but at a
previous scale (eg. not at the original size but not
at the size the image is in the view, either). Very
strange.
>
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.
I'm sorry to say that I'm still really confused by all
this - mainly by the way NSImage works, and whether I
need to be working with NSImage or an image rep. I
have been going through the section on images in
Anguish et al, which has been helpful, but I'm still
not clear on what I need to do to rectify my problem.
>
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.
Thank you, that makes sense and clarifies the source
of the problem, at least. How do I avoid losing the
extra headroom? Instead of using drawInRect to create
a new NSImage, would I instead create a new
NSBitmapImageRep by scaling the NSBitmapImageRep
underlying the current NSImage? If so, how do I get
the original NSBitmapImageRep? And would I use
addRepresentation to add the new NSBitmapImageRep to
the original image, or create a new NSImageRep and add
it to that? Or am I on completely the wrong track
here?
Just to reiterate, the aim of this code is to allow me
to drag an image from a text view into an image view,
rescale the image in the image view, and then drag it
back to the text view at the new size with no loss in
quality (the current problem).
Thanks again for the help, and many thanks in advance
to anybody who can point me in the right direction to
where I need to start to fix the problem.
Thanks,
Keith
--- Robert Clair <email@hidden> wrote:
>
> 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