2012-01-21 11 views
0

UIImageで特定のピクセルを取得する方法がありますが、うまく機能していないようです。色は正しく見えません。なぜ誰が決定できますか?UIImageでピクセルを取得する

+ (UIColor *)colorAtPixelX:(int)x Y:(int)y image:(UIImage *)img{ 

    CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(img.CGImage)); 
    const UInt8* data = CFDataGetBytePtr(pixelData); 

    int pixelInfo = ((img.size.width * y) + x) * 4; 

    UInt8 red = data[pixelInfo]; 
    UInt8 green = data[(pixelInfo + 1)]; 
    UInt8 blue = data[pixelInfo + 2]; 
    UInt8 alpha = data[pixelInfo + 3]; 
    CFRelease(pixelData); 

    UIColor *col = [UIColor colorWithRed:(red/255.0f) green:(green/255.0f) blue:(blue/255.0f) alpha:(alpha/255.0f)]; 

    return col; 

} 

答えて

0

this postをチェックしてください。 [UIColor colorWithRed:green:blue:alpha:];

を使用して、RGBAPixelインスタンスをUIColorに変換できます
関連する問題