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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-28-2010, 01:08 PM   #45 (permalink)
qwerty2k
Registered Member
 
Join Date: Mar 2010
Posts: 6
qwerty2k is on a distinguished road
Default

Code:
//Load in the image we want to analyse
	UIImage *c = [UIImage imageNamed:@"test.jpg"];
	
	//Convert image to format we can look at
	CGImageRef inImage = CGImageRetain(c.CGImage);          
    CGContextRef ctx;  
	
	//Get the pixel data from the image
	CFDataRef m_DataRef;  
	m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));  
	UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);  
    //    Byte tmpByte;  
	int length = CFDataGetLength(m_DataRef);  
	//NSLog(@"len %d", length);  
	int bytesPerPixel = 4;
	
	int imageWidth = CGImageGetWidth(inImage);
	int imageHeight = CGImageGetHeight(inImage);

        int x = 25;
        int y = 25;

int offset = 4*((imageWidth*round(Y))+round(X))
	NSLog(@"offset:%i", offset);
	m_PixelBuf[offset+1] = 255;
	m_PixelBuf[offset+2] = 1;
	m_PixelBuf[offset+3] = 1;

	//Create an image from the pixel data
	ctx = CGBitmapContextCreate(m_PixelBuf,  
								CGImageGetWidth( inImage ),  
								CGImageGetHeight( inImage ),  
								8,  
								CGImageGetBytesPerRow( inImage ),  
								CGImageGetColorSpace( inImage ),  
								kCGImageAlphaPremultipliedFirst );  
	
	
	CGImageRef imageRef = CGBitmapContextCreateImage (ctx);  
	UIImage* rawImage = [UIImage imageWithCGImage:imageRef];  
	
	CGContextRelease(ctx);  
	
	//Set the UIImage to the new image data
    testPic2.image = rawImage;
thats a rough outline of the code im using, picture im testing on is a 50px by 50px pixel just as a test yet trying to get x,y of 25,25 doesn't yield the pixel in the dead center of the image
qwerty2k is offline   Reply With Quote
 

» Advertisements
» Online Users: 351
13 members and 338 guests
bignoggins, chemistry, Domele, Duncan C, hacker073, HowEver, ilmman, krisk, mongmo, n00b, Paul Slocum, SillyHoney, timle8n1
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,560
Threads: 94,079
Posts: 402,742
Top Poster: BrianSlick (7,990)
Welcome to our newest member, mongmo
Powered by vBadvanced CMPS v3.1.0

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