Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreGraphics help



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




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.