1

タッチの現在の位置(XおよびY座標)に基づいて、画像上でユーザーの指がタッチされているピクセルカラー(RGB)を正しく取得する次のコードがあります。したがって、このコードは正常に機能しますが、網膜ディスプレイデバイスでは機能しません。

-(void)drawFirstColorWithXCoord:(CGFloat)xCoor andWithYCoord:(CGFloat)yCoor
{
    CGImageRef imageRef = [image CGImage]; //image is an ivar of type UIImage
    NSUInteger width = CGImageGetWidth(imageRef);
    NSUInteger height = CGImageGetHeight(imageRef);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    unsigned char *rawData = malloc(height * width * 4);
    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);

    //GET PIXEL FROM POINT
    int index = 4*((width*round(yCoor))+round(xCoor));

    int R = rawData[index];
    int G = rawData[index+1];
    int B = rawData[index+2];

    NSLog(@"%d   %d   %d", R, G, B);

    free(rawData);
}

網膜ディスプレイデバイスで機能させるために、このコードをどのように調整すればよいか知りたいです。

どんなアドバイスも高く評価されます。よろしくお願いします。

4

1 に答える 1