trying to save NSImage with different resolution
trying to save NSImage with different resolution
- Subject: trying to save NSImage with different resolution
- From: Alexander Cohen <email@hidden>
- Date: Fri, 29 Sep 2006 11:46:15 -0400
Hi, i wrote a function that is a NSImage category. It takes an
NSImage and returns an NSBitmapImageRep with a different DPI. I use
that bitmap to save out the data as any of the supported formats. My
problem is that the dpi seems to be coming out ok but the actual
image comes out very small and in the top left corner of the output.
What might i be doing wrong?
- (NSBitmapImageRep*)bitmapImageRepWithDpi:(float)dpi
{
float dpiRatio = dpi/72.0;
NSSize mySize = [self size];
NSRect offscreenRect = NSMakeRect(0.0, 0.0, mySize.width*dpiRatio,
mySize.height*dpiRatio);
NSRect myRect = NSMakeRect(0,0,mySize.width, mySize.height);
NSBitmapImageRep* offscreenRep = nil;
offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
pixelsWide:offscreenRect.size.width
pixelsHigh:offscreenRect.size.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:0
bytesPerRow:(4 * offscreenRect.size.width)
bitsPerPixel:32];
[offscreenRep setSize:mySize];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithBitmapImageRep:offscreenRep]];
[self drawInRect:myRect fromRect:myRect operation:NSCompositeCopy
fraction:1.0];
[NSGraphicsContext restoreGraphicsState];
return [offscreenRep autorelease];
}
thanks
AC
_______________________________________________
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