简体   繁体   English

Obj-C中的图像处理

[英]Image processing in Obj-C

I want to do some scientific image processing on iOS in Obj-C or of course C, all I require to do this is to get a 3D array of the bit values of all the pixels' RGBA. 我想在Obj-C或C语言中的iOS上进行一些科学的图像处理,我要做的就是获取所有像素RGBA的位值的3D数组。 UIImage doesn't seem to have a built in function. UIImage似乎没有内置函数。 Do any of you know how to get the pixel values or more preferably a predefined library with those functions in there? 你们中有人知道如何获取像素值,或者更优选的是在其中具有这些功能的预定义库吗? Thanks in advance, JEM 在此先感谢,JEM

You'd normally either create a CGBitmapContext , telling it to use some memory you'd allocated yourself (so, you know where it is and how to access it) or let Core Graphics figure that out for you and call CGBitmapContextGetData if you're targeting only iOS 4/OS X 10.6 and later, then draw whatever you want to inspect to it. 通常,您可以创建一个CGBitmapContext ,告诉它使用您自己分配的一些内存(因此,您知道它在哪里以及如何访问它),或者让Core Graphics为您找出问题,并在需要时调用CGBitmapContextGetData仅针对iOS 4 / OS X 10.6及更高版本,然后将要检查的内容绘制到该对象上。

Eg (error checking and a few setup steps deliberately omitted for brevity; look for variables I use despite not defining and check the function documentation) 例如(为简洁起见,故意省略了错误检查和一些设置步骤;查找尽管未定义但仍使用的变量并检查功能文档)

CGBitmapInfo bitmapInfo =
              kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;

context =
       CGBitmapContextCreate(
                NULL,
                width, height,
                8,
                width * 4,
                rgbColourSpace,
                bitmapInfo);

CGContextDrawImage(
        context,
        CGRectMake(0.0f, 0.0f, (CGFloat)width, (CGFloat)height),
        [image CGImage]);

uint8_t *pixelPointer = CGBitmapContextGetData(context);

for(size_t y = 0; y < height; y++)
{
    for(size_t x = 0u; x < width; x++)
    {
        if((bitmapInfo & kCGBitmapByteOrder32Little))
        {
            NSLog(@"rgba: %02x %02x %02x %02x",
                 pixelPointer[2], pixelPointer[1],
                 pixelPointer[0], pixelPointer[3]);
        }
        else
        {
            NSLog(@"rgba: %02x %02x %02x %02x",
                 pixelPointer[1], pixelPointer[2],
                 pixelPointer[3], pixelPointer[0]);
        }

        pixelPointer += 4;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM