Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-28-2009, 04:01 PM   #3 (permalink)
jcafaro10
Registered Member
 
Join Date: Feb 2009
Posts: 88
Default

Quote:
Originally Posted by Delirium View Post
I believe all Quartz color and alpha values are floats between 0.0 and 1.0, where 0.0 would be 0, and 1.0 would be your 255.
How does an image get turned into a data array specifically? I'm trying to figure out why I'm getting bad accesses on some images. I think it has to do with how I'm calculating the byteIndex but not sure. The problem occurs at some point during the for loop where the byteIndex is becomes the size of the rawData array which is obviously not good.

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;
int size = height*width*bytesPerPixel;	
	unsigned char *rawData = malloc(size); 
	CGContextRef context = CGBitmapContextCreate(rawData,width,height,bitsPerComponent,bytesPerRow,colorSpace,kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGColorSpaceRelease(colorSpace);
	CGContextDrawImage(context, CGRectMake(0,0,width,height),image);
	CGContextRelease(context);
	
	for(int x = 0; x < width; x++)
	{
		for(int y = 0; y < height; y++)
		{
			int byteIndex = (bytesPerRow * x) + y * bytesPerPixel; 	
			int red = rawData[byteIndex];
			int green = rawData[byteIndex+1];
			int blue = rawData[byteIndex+2];
		    int alpha = rawData[byteIndex+3];
			//printf("%d,%d: %d,%d,%d,%d\n",x,y,red,green,blue,alpha);
		}
	}
jcafaro10 is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,130
Threads: 38,899
Posts: 170,659
Top Poster: smasher (2,565)
Welcome to our newest member, HunBirk427
Powered by vBadvanced CMPS v3.1.0

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