Re: Switching off antialiasing...
Re: Switching off antialiasing...
- Subject: Re: Switching off antialiasing...
- From: Stefan Jung <email@hidden>
- Date: Thu, 19 Jul 2001 12:41:27 +0200
Am Donnerstag, 19. Juli 2001 um 11:22 schrieb Marcel Weiher:
On Thursday, July 19, 2001, at 10:30 Uhr, Stefan Jung wrote:
...is very easy for the on screen display. But what is the trick to
do this with an image?
Just the same...
I already guessed that. But something in my guess is yet wrong:-)
I tried a lot with lockig focus and so on...no chance. The TIFF I
want to save is always antialiased, regardless it is set or not.
That's because the conversion to TIFF is not happening where you
think it's happening.
OK.
My code:
-(void)saveAsTIFF:sender
{
NSImage *specImage;
NSSavePanel *sp;
int result;
NSGraphicsContext *graphicsContext;
specImage = [[NSImage alloc] initWithSize:[self bounds].size];
[specImage lockFocus];
graphicsContext = [NSGraphicsContext currentContext];
[graphicsContext setShouldAntialias:NO];
[specImage initWithData:[self dataWithPDFInsideRect:[self
bounds]]];
This initializes the specImage with the PDF-representation of your
view. It doesn't actually render anything. It is also wrong in
that you're sending an -init... message to an NSImage that's
already been initialized.
If the image is not inited [specImage lockFocus] the following
happens: Indeed it's no crash, but while debugging and stepping
over [specImage lockFocus] the program runs and never returns into
my SaveAsTIFF subroutine. Quitting the program then crashes
Project Builder.
Try [self drawRect:[self bounds]] instead (not 100% sure, but
it's the right direction, somehow I think [self frame] would be
better)
Autsch! Of course this works. I was so befiddelt by all those many
methods I forgot to try the obvious.
I remember I had that in mind...once upon a time:-)
[specImage unlockFocus];
sp = [NSSavePanel savePanel];
[sp setRequiredFileType:@"TIFF"];
result = [sp runModalForDirectory:NSHomeDirectory() file:[[self
window] title]];
if (result == NSOKButton) {
if (![[specImage TIFFRepresentation] writeToFile:[sp
filename] atomically:YES])
This is where the rendering is taking place in your example,
Sure?
and since the current-context has changed again, you're not
seeing the effects of setAntiAlias of the previous context.
Now that I have changed from "[specImage initWith
Data:[self
dataWithPDFInsideRect:[self bounds]]];" to "[self drawRect:[self
bounds]];" it works the way I want. I have not added an additional
"[graphicsContext setShouldAntialias:NO];". If the rendering
happens here, and indeed the specImage has to generate a bitmap
here, than the image remembers the previous alias setting.
If I now only could make a PICT out of it. Seufz.
Stefan Jung