Re: compositeToPoint ignores DPI?
Re: compositeToPoint ignores DPI?
- Subject: Re: compositeToPoint ignores DPI?
- From: Ben Mackin <email@hidden>
- Date: Wed, 20 Nov 2002 14:16:31 -0800
On 10/28/02 2:20 PM, "Ali Ozer" <email@hidden> wrote:
>
Actually compositeToPoint: does not ignore the dpi; I would guess
>
what's happening is your image is being loaded, then the pixel size
>
reduced by applying the dpi --- So if your image was 209pixels x
>
209pixels, say, and your dpi is 209dpi, the image is displayed as 1inch
>
x 1inch, which is 72pixels x 72pixels. (In fact this is what the "size"
>
method should be reporting).
>
>
<snip>
>
>
Note that if you want the resulting image (myImageToSave in your
>
example) to have all the pixels of the original, then it gets a little
>
trickier --- you need to create the image at the appropriate pixel size
>
(so, 209x209 instead of 72x72 in the above example), but use setSize:
>
on the bitmap image rep to set the resolution properly. In this case
>
you might also want to use -[NSImage
>
drawInRect:fromRect:operation:fraction:] to draw the image scaled,
>
rather than compositeToPoint:operation:. compositing, by definition,
>
ignores the destination CTM when drawing.
Ok, I have been trying to figure this out, but I just can't seem to get it
to output the correct image. The image comes out the correct size and DPI,
but it is just completely black, as if the image is not drawn at all. I also
tried drawInRect , but get the same result.
Something interesting, but if I change the second to last line to read:
NSData *myNewData = [myImageToSave TIFFRepresentation];
The image comes out looking ok, but it is 1726x2156 with a resolution of 72,
72 pixels/inch. The code I am using looks like:
(In case you didn't know, 612x792 is US letter size in pixels).
NSImage *myImageToSave;
NSImage *myImage = [[NSImage alloc] initWithContentsOfFile:@"/here.tif"];
mySize = [myImage size];
float hres, vres;
NSImageRep *myRep = [[myImage representations] objectAtIndex:0];
hres = [myRep pixelsWide]/mySize.width;
vres = [myRep pixelsHigh]/mySize.height;
myImageToSave = [[NSImage alloc] initWithSize:NSMakeSize(612*(hres),
792*(vres))];
NSBitmapImageRep *myOtherRep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:[myRep pixelsWide]
pixelsHigh:[myRep pixelsHigh]
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0
bitsPerPixel:0];
[myImageToSave addRepresentation:myOtherRep];
[myOtherRep setSize:NSMakeSize(largestPageWidth,largestPageHeight)];
[myImage setCacheMode:NSImageCacheNever];
[myImageToSave lockFocusOnRepresentation:myOtherRep];
[myImage compositeToPoint:NSMakePoint(0, 0) operation:NSCompositeCopy];
[myImageToSave unlockFocus];
NSData *myNewData = [myOtherRep TIFFRepresentation];
[myNewData writeToFile:@"/here.tif" atomically:YES];
Thanks,
Ben
http://www.shayufilms.com
_______________________________________________
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.