Re: Properly dealing with images
Re: Properly dealing with images
- Subject: Re: Properly dealing with images
- From: Michael Becker <email@hidden>
- Date: Thu, 17 Jun 2004 15:47:47 +0200
Am Jun 17, 2004 um 11:39 AM schrieb Michael Becker:
NSImage doesn't seem to take into account that there are different
image resolutions. I have a 1800 x 1800 pixel image at 20 pixels per
inch. NSImage tells me that it's 6480 x 6480 pixels (which would be
true if it was at the standard 72 pixels per inch).
Ok, I am using NSBitmapImageRep's pixelsHigh and pixelsWide, which
works fine. But I realised another issue:
Say, I have a 300dpi JPEG image. I load it into an NSImage (using
initWithContentsOfFile:). Then I do something with it (manipulate in
whatever way, say, render an NSAttributedString on the image). Now I
want to save this image to disk, using the exact same properties as the
loaded image had. This code:
NSImage* theImage;
. . .
NSData* data = [ theImage TIFFRepresentation];
NSBitmapImageRep *imageRep = [ NSBitmapImageRep
imageRepWith
Data:[[[NSImage alloc] initWith
Data:data]
TIFFRepresentation]];
NSDictionary *propDict = [ NSDictionary
dictionaryWithObjectsAndKeys:[ NSNumber numberWithFloat:1.0],
NSImageCompressionFactor, nil];
[[ imageRep representationUsingType:NSJPEGFileType
properties:propDict] writeToFile:path atomically:YES];
Always produces a typical 72dpi-JPEG-image.
What can I do? Actually, the most important thing is to preserve the
pixel-dimensions. That means, I don't really care about the dpi, but
the output image needs to have the same pixel-width / pixel-height as
the original. Being a newbie to this image manipulation myself, I hope
that somebody understands what I am saying :-)
Cheers,
Michael
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.