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, 05: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
 

» Advertisements
» Stats
Members: 158,561
Threads: 89,129
Posts: 380,270
Top Poster: BrianSlick (7,105)
Welcome to our newest member, lance56br
Powered by vBadvanced CMPS v3.1.0

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