3 回答
TA貢獻1877條經驗 獲得超6個贊
您無法直接訪問原始數據,但通過獲取此圖像的CGImage,您可以訪問它。這里是另一個問題的鏈接,可以回答您的問題以及您可能擁有的有關詳細圖像處理的其他問題:CGImage
TA貢獻1805條經驗 獲得超10個贊
試試這個非常簡單的代碼:
我曾經在我的迷宮游戲中檢測到墻壁(我需要的唯一信息是alpha通道,但我包含了代碼以獲取其他顏色):
- (BOOL)isWallPixel:(UIImage *)image xCoordinate:(int)x yCoordinate:(int)y {
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage));
const UInt8* data = CFDataGetBytePtr(pixelData);
int pixelInfo = ((image.size.width * y) + x ) * 4; // The image is png
//UInt8 red = data[pixelInfo]; // If you need this info, enable it
//UInt8 green = data[(pixelInfo + 1)]; // If you need this info, enable it
//UInt8 blue = data[pixelInfo + 2]; // If you need this info, enable it
UInt8 alpha = data[pixelInfo + 3]; // I need only this info for my maze game
CFRelease(pixelData);
//UIColor* color = [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha/255.0f]; // The pixel color info
if (alpha) return YES;
else return NO;
}
- 3 回答
- 0 關注
- 534 瀏覽
添加回答
舉報
