Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-28-2009, 12:07 PM   #1 (permalink)
jcafaro10
Registered Member
 
Join Date: Feb 2009
Posts: 88
Default Bitmaps, Quartz, confusion...

Hey all, I've been searching around for some tutorials on doing things with bitmaps with quartz. I'm very new to this but stumbled upon some tutorials and here is the code that I came up with to start off.


Code:
CGImageRef image = [imageView.image CGImage];
	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
	NSUInteger width = CGImageGetWidth(image);
	NSUInteger height = CGImageGetHeight(image);
	NSUInteger bytesPerPixel = 4;
	NSUInteger bytesPerRow = bytesPerPixel * width;
	NSUInteger bitsPerComponent = 8;
	unsigned char *rawData = malloc(height*width*bytesPerPixel); 
	CGContextRef context = CGBitmapContextCreate(rawData,width,height,bitsPerComponent,bytesPerRow,colorSpace,kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGColorSpaceRelease(colorSpace);
	CGContextDrawImage(context, CGRectMake(0,0,width,height),image);
	CGContextRelease(context);
    int byteIndex = (bytesPerRow * 100) + 100 * bytesPerPixel;
	char red = rawData[byteIndex];
	char green = rawData[byteIndex+1];
	char blue = rawData[byteIndex+2];
	char alpha = rawData[byteIndex+3];
	printf("100,100:%c,%c,%c,%c \n",red,green,blue,alpha);
Here's what I understand (or at least think I understand from reading the quartz programming guide and some other things).

CGImageRef basically just holds a certain version of the UIImage on my screen that I can mess around with. I'm not sure what the color space but I assume it has to do with figuring out how to interpret RGB components. Next I get the width and height of the image. I set some fields like bytesPerPixel (how many bytes to use to represent each pixel) and bitsPerComponent. If bytes per pixel is 4, does that mean 1 byte for Red, 1 for Blue, 1 for Green, 1 for Alpha? I suppose that goes with bitspercomponent = 8 since 8 bits is a byte.

Then I make the context which I imagine basically just says, where should the drawing of this image occur, then I draw it there. So now rawData should have all of my bitmap data. Then I tried to see what was actually in the array so I picked a random coordinate (100,100) and tried to see what the RGB components were but I didn't get numbers between 0-255 which is what I thought I'd expect.

Is my interpretation of what's going on here reasonably correct?
jcafaro10 is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,825
Threads: 89,207
Posts: 380,637
Top Poster: BrianSlick (7,129)
Welcome to our newest member, srishtimehta
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:45 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.