Re: clear a CGContextRef in an iPhone app
Re: clear a CGContextRef in an iPhone app
- Subject: Re: clear a CGContextRef in an iPhone app
- From: Rainer Standke <email@hidden>
- Date: Mon, 4 Oct 2010 11:34:23 -0700
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:
CGContextRef context = 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 (email@hidden)
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:
This email sent to email@hidden