지금 다음을 수행하려고 몇 시간 동안 있었다,CGImageCreate는 Completly 검은 부여하거나 어떤 이미지 또는 충돌
- 플레이어는 플레이어가 도청 한 픽셀의 값을 가져 화면을
- 도청
- 화상 통한 루프는 픽셀이 새롭게 생성 같이있는 UIImage 설정 동일한 동일 값을 가진 모든
- 화소가 0의 알파는 새로운 이미지를 만들도록하고
- 아르 알 하나 012,351,
- ...
- 이익
그러나 제목이 말한다 완전히 검은 화면이나 이미지가 전혀 ... 아마도 어쩌면 모두 0으로 알파를 설정하지 않기 때문에 그 중 하나가해야 할 것, 또는 뭔가 충돌 이 기능 여기 CGSConvertBGRX8888toRGBA8888
근처 스택에 나쁜 액세스에 대한 기능을
+ (UIImage*)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy
{
입니다 51,515,// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
NSUInteger bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
NSUInteger bitsPerPixel = CGImageGetBitsPerPixel(imageRef);
NSUInteger bytesPerRow = CGImageGetBytesPerRow(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = (unsigned char*) malloc(height * width * 4);
CGContextRef context = CGBitmapContextCreate(rawData,
width,
height,
bitsPerComponent,
bytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGContextClearRect(context, CGRectMake(0, 0, width, height));
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
//convert phone screen coords to texture coordinates.
xx *= width/320;
yy *= height/480;
int counter = 0;
// Now your rawData contains the image data in the RGBA8888 pixel format.
// Get the byteIndex of pixel tapped.
int byteIndex = (bytesPerRow * yy) + xx * bitsPerPixel;
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 = (width * y) + x * bitsPerPixel;
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 + 3] = 0;
counter ++;
}
}
}
}
NSLog(@"Pixels amount: %i", counter);
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL,
rawData,
width*height*4,
NULL);
CGImageRef newCGimage = CGImageCreate(width,
height,
bitsPerComponent,
bitsPerPixel,
bytesPerRow,
colorSpace,
kCGBitmapByteOrderDefault,
provider,
NULL, NO, kCGRenderingIntentDefault);
UIImage *newImage = [UIImage imageWithCGImage:newCGimage];
CGDataProviderRelease(provider);
CGImageRelease(newCGimage);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
free(rawData);
return newImage;
}
제가 몇몇 시험을 통해 정확한 화소를 획득하고 일부 잘 작동하는 것 같은 도면에 선택된 색상을 출력하고 매우 확신, I는 잔상을 작성하고있을 때 보인다 원시 데이터를 편집하는 것은 최소한 그것이 문제가 있다고 생각하는 부분입니다.
사전에 도움을 청합니다.
편집: 지금 코드 때문에 본질적으로이하는 모든 원시 데이터에 PNG를 복사입니다 박탈 한
가에서있는 UIImage를 생성하고 설정, 기본적으로 내가 다시 똑같은 이미지를 얻을해야하며, 아무것도 변경하지합니다 . 그러나이 시간은 그냥 내가 다른 사람의 예에 따라 잘 나는 그것을 해결 한
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
NSUInteger bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
NSUInteger bitsPerPixel = CGImageGetBitsPerPixel(imageRef);
NSUInteger bytesPerRow = CGImageGetBytesPerRow(imageRef);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);
CGBitmapInfo imageInfo = CGImageGetBitmapInfo(imageRef);
unsigned char *rawData = (unsigned char*) malloc(height * width * 4);
CGContextRef context = CGBitmapContextCreate(rawData,
width,
height,
bitsPerComponent,
bytesPerRow,
colorSpace,
imageInfo);
//convert phone screen coords to texture coordinates.
xx *= (width/[[UIScreen mainScreen] bounds].size.width);
yy *= (height/[[UIScreen mainScreen] bounds].size.height);
NSLog(@"converted X pos: %i",xx);
NSLog(@"converted Y pos: %i",yy);
int counter = 0;
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL,
rawData,
width*height*4,
NULL);
CGImageRef newCGimage = CGImageCreate(width,
height,
bitsPerComponent,
bitsPerPixel,
bytesPerRow,
colorSpace,
imageInfo,
provider,
NULL, NO, kCGRenderingIntentDefault);
UIImage *newImage = [[UIImage alloc]initWithCGImage:newCGimage];
CGDataProviderRelease(provider);
CGImageRelease(newCGimage);
CGContextRelease(context);
free(rawData);
return newImage;