zoukankan      html  css  js  c++  java
  • 获取图片像素信息

    - (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)x andY:(int)y count:(int)count
    {
        NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:count];
        
        // 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 your rawData contains the image data in the RGBA8888 pixel format.
        NSUInteger byteIndex = (bytesPerRow * y) + x * bytesPerPixel;
        for (int i = 0 ; i < count ; ++i)
        {
            CGFloat alpha = ((CGFloat) rawData[byteIndex + 3] ) / 255.0f;
            CGFloat red   = ((CGFloat) rawData[byteIndex]     ) / alpha;
            CGFloat green = ((CGFloat) rawData[byteIndex + 1] ) / alpha;
            CGFloat blue  = ((CGFloat) rawData[byteIndex + 2] ) / alpha;
            byteIndex += bytesPerPixel;
            
            UIColor *acolor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
            
            [result addObject:acolor];
        }
        free(rawData);
        
        return result;
    }

    http://stackoverflow.com/questions/448125/how-to-get-pixel-data-from-a-uiimage-cocoa-touch-or-cgimage-core-graphics

    __block NSString *leftStr = @"FirstLeft";

        

        NSString *centrStr = @"FirstCenter";

        

        NSString* (^myBlock)(NSString *) = ^(NSString *lastStr){

            

            return [leftStr stringByAppendingString:[NSString stringWithFormat:@", %@, %@", centrStr, lastStr]];

        };

        

        NSLog(@"%@", myBlock(@"last"));

        

        leftStr = @"ThenLeft";

        centrStr = @"ThenCenter";

        

        NSLog(@"%@", myBlock(@"right"));

  • 相关阅读:
    ios逆向工程-内部钩子(Method Swizzling)
    ios逆向工程-动态分析
    ios逆向工程-静态分析
    Android Hook神器:XPosed入门与登陆劫持演示
    Android HOOK工具Cydia Substrate使用详解
    Android Hook框架Xposed详解
    Android Hook 框架 Cydia_substrate 详解
    Android上玩玩Hook:Cydia Substrate实战
    iOS8扩展插件开发配置 [转载]
    SQL触发器调用.NET的类方法
  • 原文地址:https://www.cnblogs.com/wly314/p/5354532.html
Copyright © 2011-2022 走看看