Re: CGBitmapContextCreate hates me
Re: CGBitmapContextCreate hates me
- Subject: Re: CGBitmapContextCreate hates me
- From: Jim Turner <email@hidden>
- Date: Mon, 20 Mar 2006 17:11:14 -0600
- Thread-topic: CGBitmapContextCreate hates me
On 3/20/06 3:17 PM, "Scott Thompson" <email@hidden> wrote:
>
> On Mar 20, 2006, at 9:11 AM, Jim Turner wrote:
>
>> I'm trying to write a simple image scaler and from examples I found,
>> CoreGraphics should be able to do what I need. The problem arises when I
>> attempt to create a new bitmap context to write the scaled image into. The
>> relevant code:
>>
>> CGContextRef newImgSetup;
>> CGImageAlphaInfo alphaInfo;
>> CGColorSpaceRef colorSpace;
>> size_t components;
>> size_t width;
>> size_t height;
>> size_t bitsPerComponent;
>> size_t bytesPerRow;
>> size_t dataLength;
>> void *data = NULL;
>>
>> alphaInfo = kCGImageAlphaNone;
>> colorSpace = CGColorSpaceCreateDeviceRGB();
>> components = CGColorSpaceGetNumberOfComponents( colorSpace );
>> width = 300;
>> height = 250;
>> bitsPerComponent = 8;
>> bytesPerRow = (width * bitsPerComponent * components + 7)/8;
>> dataLength = bytesPerRow * height;
>>
>> data = malloc( dataLength );
>> memset( data, 0, dataLength );
>>
>> newImgSetup = CGBitmapContextCreate( data, width, height, bitsPerComponent,
>> bytesPerRow, colorSpace, alphaInfo );
>
> Core Graphics doesn't support RGB Bitmap contexts (i.e. ones with no storage
> for alpha channel). Set your components to 4 and
> use kCGImageAlphaNoneSkipFirst or kCGImageAlphaNoneSkipLast. (depending on
> your desires).
>
> see also:
>
> <http://developer.apple.com/qa/qa2001/qa1037.html>
>
> Scott
>
Bah, you know as soon as I read that, it clicked what I had read about 24
bit bitmaps not being supported. I just didn¹t see that I was asking CG for
a 24bit context. It works now (albeit I get a solid black image for
output... hrm).
Thanks Scott
--
Jim Turner
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