1
rshinich 315 天前
试试直接用 CGImage 呢?然后用这个: https://developer.apple.com/documentation/coregraphics/cgdataprovider
|
2
653513754 315 天前
```
UIImage *origImg = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%s",imgPath]]; //加载图片 CGSize size = [origImg size]; int width = size.width; int height = size.height; uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t)); memset(pixels, 0, width * height * sizeof(uint32_t)); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast); CGContextDrawImage(context, CGRectMake(0, 0, width, height), [origImg CGImage]); int tt = 1; CGFloat intensity; int bw; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x]; // rgbaPixel[tt] + rgbaPixel[tt + 1] + rgbaPixel[tt + 2] 像素点 } } CGImageRef image = CGBitmapContextCreateImage(context); CGContextRelease(context); CGColorSpaceRelease(colorSpace); free(pixels); ``` |