• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
trying to save NSImage with different resolution
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Rounding the output value while the slider is being moved (From: Artemiy Pavlov <email@hidden>)
 >Re: Rounding the output value while the slider is being moved (From: Artemiy Pavlov <email@hidden>)
 >Re: Rounding the output value while the slider is being moved (From: Hank Heijink <email@hidden>)
 >Re: Rounding the output value while the slider is being moved (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: Rounding the output value while the slider is being moved
  • Next by Date: Re: Thoroughly confused on date formatting
  • Previous by thread: Re: Rounding the output value while the slider is being moved
  • Next by thread: Animation during scrollbar tracking
  • Index(es):
    • Date
    • Thread