내 목표는 다음과 같습니다.아이폰 픽셀 RGBA 값 편집
플레이어가 화면을 터치하면 프로그램은 터치 한 위치의 픽셀 값을 찾아 모든 픽셀을 반복해야하며 정확한 RGBA 값을 가진 모든 것은 편집됩니다. 알파를 모두 보이지 않게하려면 0으로 설정하고 싶습니다.
지금까지 나는 그 정보를 은퇴 할 수 있었지만 어떤 것들은 터치 된 픽셀에 해당하는지 알아 냈습니다. 그러나 픽셀을 설정하고 새 데이터에서 UIImage를 만들고 설정했습니다. 아무것도 바뀌지 않습니다.
약간의 도움을 많이 주시면 감사하겠습니다. (있는 UIImage *) 화상 ATX : (INT) XX ANDY (INT) YY
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
//convert phone screen coords to texture coordinates.
xx *= width/[[UIScreen mainScreen] bounds].size.width;
yy *= height/[[UIScreen mainScreen] bounds].size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char));
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
/* MY STUFF */
int counter = 0;
/* MY STUFF */
// Now your rawData contains the image data in the RGBA8888 pixel format.
// Get the byteIndex of pixel tapped.
int byteIndex = (bytesPerRow * yy) + xx * bytesPerPixel;
CGFloat red = (rawData[byteIndex] * 1.0)/255.0;
CGFloat green = (rawData[byteIndex + 1] * 1.0)/255.0;
CGFloat blue = (rawData[byteIndex + 2] * 1.0)/255.0;
CGFloat alpha = (rawData[byteIndex + 3] * 1.0)/255.0;
byteIndex += 4;
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
byteIndex = (x + (y * width)) * bytesPerPixel;
CGFloat redVal = (rawData[byteIndex] * 1.0)/255.0;
CGFloat greenVal = (rawData[byteIndex + 1] * 1.0)/255.0;
CGFloat blueVal = (rawData[byteIndex + 2] * 1.0)/255.0;
CGFloat alphaVal = (rawData[byteIndex + 3] * 1.0)/255.0;
byteIndex += 4;
if(alphaVal != 0)
{
if(redVal == red && greenVal == green && blueVal == blue)
{
rawData[byteIndex] = 255;
rawData[byteIndex + 1] = 255;
rawData[byteIndex + 2] = 255;
rawData[byteIndex + 3] = 1;
counter ++;
}
}
}
}
UIImage *newImage = [UIImage imageWithCGImage: imageRef];
image = newImage;
NSLog(@"Pixels amount: %i", counter);
free(rawData);
return image;
및 호출 될
코드
함수가 가
(있는 UIImage *) getRGBAsFromImage가 을
이하 like sotempBGRef.image = [MainMenuViewController getRGBAsFromImage:[tempBGRef image] atX:touchPointInView.x andY:touchPointInView.y];
환호 ... 불행히도 나는 알아야 할 많은 분야가 있습니다. 코드 샘플로 raw 데이터 배열 – Genhain
Google을 사용하는 경우가 아니면 - 많이 있어야합니다. –