相关疑难解决方法(0)

如何比较UIColors?

我想在UIImageView上检查背景的颜色集.我试过了:

if(myimage.backgroundColor == [UIColor greenColor]){
...}
else{
...}
Run Code Online (Sandbox Code Playgroud)

但这不起作用,即使我知道颜色是绿色,它总是落入其他部分.

还有,有办法在调试控制台中输出当前颜色.

p [myimage backgroundColor]
Run Code Online (Sandbox Code Playgroud)

po [myimage backgroundColor]
Run Code Online (Sandbox Code Playgroud)

不工作.

cocoa-touch objective-c uiimageview uicolor ios

125
推荐指数
7
解决办法
5万
查看次数

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

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

-(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万
查看次数

标签 统计

ios ×2

cocoa-touch ×1

iphone ×1

objective-c ×1

paint ×1

pixel ×1

touch ×1

uicolor ×1

uiimageview ×1