相关疑难解决方法(0)

如何在触摸时获得像素颜色?

我知道这是一个常见的问题,这个问题有很多答案.我已经使用了其中一些.虽然其中很多都是一样的.但令我伤心的是,他们都没有为我工作.以下我用过的代码.

-(void)getRGBAsFromImage:(UIImage*)image 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);
    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);

    // Now …
Run Code Online (Sandbox Code Playgroud)

iphone pixel paint touch ios

23
推荐指数
4
解决办法
1万
查看次数

Swift OpenGL未解析的标识符kCGImageAlphaPremultipliedLast

我收到'kCGImageAlphaPremultipliedLast'的未解决的标识符错误.斯威夫特找不到它.这可以在Swift中使用吗?

var gc = CGBitmapContextCreate(&pixelData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: width*4, imageCS, bitmapInfo: kCGImageAlphaPremultipliedLast);
Run Code Online (Sandbox Code Playgroud)

opengl-es ios swift

10
推荐指数
1
解决办法
3293
查看次数

标签 统计

ios ×2

iphone ×1

opengl-es ×1

paint ×1

pixel ×1

swift ×1

touch ×1