• 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
Re: WebConvertNSImageToCGImageRef Issues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WebConvertNSImageToCGImageRef Issues


  • Subject: Re: WebConvertNSImageToCGImageRef Issues
  • From: John Pannell <email@hidden>
  • Date: Sun, 15 Jan 2006 22:51:17 -0700

Hi Chad-

Not sure if you were more interested in getting the WebConvert function to work (which I know nothing about) or if you wanted a good method to make a CGImageRef (which I can help with). Here's a C function I use to load CGImageRefs from a PNG image file in my bundle...

CGImageRef loadImageNamed(NSString *name)
{
CFURLRef thisURL = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)[[NSBundle mainBundle] pathForImageResource:name], kCFURLPOSIXPathStyle, false);
if(thisURL == NULL){
NSLog(@"couldn't create URL!");
return nil;
}
CGDataProviderRef thisDataProvider = CGDataProviderCreateWithURL (thisURL);
CFRelease(thisURL);
if(thisDataProvider == NULL){
NSLog(@"couldn't create data provider");
return nil;
}
CGImageRef thisImageRef = CGImageCreateWithPNGDataProvider (thisDataProvider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(thisDataProvider);
if(thisImageRef == NULL){
NSLog(@"couldn't create imageRef");
return nil;
}
return thisImageRef;
}


to call it...

CGImageRef myQuartzImage = loadImageNamed(@"myImage");

In your code, there might be an issue (although I would think XCode would have warned you) with the "unLockFocus" method - I believe it is "unlockFocus" without the capital L.

HTH!

John


On Jan 15, 2006, at 10:37 PM, Chad Weider wrote:

I seem to be getting odd results when using WebKit's WebConvertNSImageToCGImageRef to convert NSImages to their CGImage counterparts...

This code works fine:
	NSImage *theImage = [NSImage imageNamed:@"NSApplicationIcon"];
	CGImageRef theRef = WebConvertNSImageToCGImageRef(theImage);

	[theImage lockFocus];
	//Some Drawing
	[theImage unLockFocus];

	if(theImage != nil && theRef == nil)
		NSLog(@"wtf");

...just that drawing code won't take effect


And this will log wtf everytime: NSImage *theImage = [NSImage imageNamed:@"testImage.png"]; CGImageRef theRef = WebConvertNSImageToCGImageRef(theImage); [theImage lockFocus]; //Some Drawing [theImage unLockFocus];

	if(theImage != nil && theRef == nil)
		NSLog(@"wtf");

...but if the lockFocus stuff is removed, it passes.

Any ideas?

...apple's documentation on the function is pretty nonexistent...so I would think there shouldn't be any suprises in-store for me, eh?

Chad Weider
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40positivespinmedia.com


This email sent to email@hidden

_______________________________________________ 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
  • Follow-Ups:
    • Re: WebConvertNSImageToCGImageRef Issues
      • From: Chad Weider <email@hidden>
References: 
 >WebConvertNSImageToCGImageRef Issues (From: Chad Weider <email@hidden>)

  • Prev by Date: WebConvertNSImageToCGImageRef Issues
  • Next by Date: Re: create a graph with cocoa
  • Previous by thread: WebConvertNSImageToCGImageRef Issues
  • Next by thread: Re: WebConvertNSImageToCGImageRef Issues
  • Index(es):
    • Date
    • Thread