Re: clear a CGContextRef in an iPhone app
On Oct 4, 2010, at 11:04 AM, Rainer Standke wrote: wondering how to clear a context. I'm using this: CGContextClearRect(context, drawingRect); But yet, afetr I do that, and then start to draw something new, I get remnants of the previous content of the context. Where are you calling this? About the only thing I know of that might cause this is trying to call UIGraphicsGetCurrentContext() from outside of -drawRect: (in which case unless you've pushed or started your own context you get back NULL, which CG ignores). -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: clear a CGContextRef in an iPhone app
This is indeed outside of -drawRect, and it's a context I create myself, like so: // returns a new 'abstract' graphics context to draw in: CGContextRefcontext = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow = (pixelsWide * 4); bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); colorSpace = CGColorSpaceCreateDeviceRGB(); bitmapData = malloc( bitmapByteCount ); if (bitmapData == NULL) { fprintf (stderr, Memory not allocated!); return NULL; } context = CGBitmapContextCreate (bitmapData, pixelsWide, pixelsHigh, 8, // bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); if (context== NULL) { free (bitmapData); fprintf (stderr, Context not created!); return NULL; } CGColorSpaceRelease( colorSpace ); CGContextSetAllowsAntialiasing(context, YES); CGContextSetShouldAntialias(context, YES); return context; Rainer On Oct 4, 2010, at 11:15 , David Duncan wrote: On Oct 4, 2010, at 11:04 AM, Rainer Standke wrote: wondering how to clear a context. I'm using this: CGContextClearRect(context, drawingRect); But yet, afetr I do that, and then start to draw something new, I get remnants of the previous content of the context. Where are you calling this? About the only thing I know of that might cause this is trying to call UIGraphicsGetCurrentContext() from outside of -drawRect: (in which case unless you've pushed or started your own context you get back NULL, which CG ignores). -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: clear a CGContextRef in an iPhone app
On Oct 4, 2010, at 11:34 AM, Rainer Standke wrote: This is indeed outside of -drawRect, and it's a context I create myself, like so: Then you will need to show more code, specifically the code that is showing the issue you are experiencing, because none of the code you've shown thus far should be causing any problems. -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: clear a CGContextRef in an iPhone app
I have to wonder why you're going to all this trouble when UIGraphicsBeginImageContext exists. What exactly are you planning on doing, ultimately, with this context? And why do you need to clear the entire thing after you've drawn into it? m. On Mon, 4 Oct 2010 11:34:23 -0700, Rainer Standke li...@standke.com said: This is indeed outside of -drawRect, and it's a context I create myself, like so: // returns a new 'abstract' graphics context to draw in: CGContextRefcontext = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow = (pixelsWide * 4); bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); colorSpace = CGColorSpaceCreateDeviceRGB(); bitmapData = malloc( bitmapByteCount ); if (bitmapData == NULL) { fprintf (stderr, Memory not allocated!); return NULL; } context = CGBitmapContextCreate (bitmapData, pixelsWide, pixelsHigh, 8, // bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); if (context== NULL) { free (bitmapData); fprintf (stderr, Context not created!); return NULL; } CGColorSpaceRelease( colorSpace ); CGContextSetAllowsAntialiasing(context, YES); CGContextSetShouldAntialias(context, YES); return context; Rainer On Oct 4, 2010, at 11:15 , David Duncan wrote: On Oct 4, 2010, at 11:04 AM, Rainer Standke wrote: wondering how to clear a context. I'm using this: CGContextClearRect(context, drawingRect); But yet, afetr I do that, and then start to draw something new, I get remnants of the previous content of the context. Where are you calling this? About the only thing I know of that might cause this is trying to call UIGraphicsGetCurrentContext() from outside of -drawRect: (in which case unless you've pushed or started your own context you get back NULL, which CG ignores). -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com