CoreGraphics help
CoreGraphics help
- Subject: CoreGraphics help
- From: Hisaoki Nishida <email@hidden>
- Date: Thu, 19 Jul 2001 13:48:41 -0400
Hi,
I am trying to draw an image to a CG context in a widow that I've set up
with it.
I have no idea what's wrong with my code, I'd appreciate any help.
The window renders fine. But drawing the image is the part I'm having
trouble with.
The image I think is loaded fine because I can see it load in the build
log.
Here's the code:
// Obtaining the path for image
bundle = [NSBundle bundleForClass:[self class]];
path = [bundle pathForResource:@"logo_yggdral" ofType:@"tiff"];
url = [NSURL fileURLWithPath:path];
// Setting up a window
window = [[NSWindow alloc]
initWithContentRect:NSMakeRect( 0, 0, kDesiredWidth,
kDesiredHeight )
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreNonretained
defer:NO];
[window makeKeyAndOrderFront:window];
[[window contentView] lockFocusIfCanDraw];
context = [[NSGraphicsContext currentContext] graphicsPort];
provider = CGDataProviderCreateWithURL( url );
colorSpace = CGColorSpaceCreateDeviceRGB();
image = CGImageCreate( 128,
128,
8,
32,
4 * 128,
colorSpace,
kCGImageAlphaFirst,
provider,
NULL,
0,
kCGRenderingIntentDefault );
CGDataProviderRelease( provider );
CGContextDrawImage( context,
CGRectMake( 0, 0, 128, 128 ),
image );
CGImageRelease( image );
Thank you,
HN