所有我想要做的就是檢查特定像素的RGB值,並且與其旁邊的像素相同,並將第一個像素的RGB值設置爲兩個像素的RGB之間的範圍值UIImage像素設置RGB值
這裏的代碼
int width = img.size.width;
int height = img.size.height;
// the pixels will be painted to this array
uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));
// clear the pixels so any transparency is preserved
memset(pixels, 0, width * height * sizeof(uint32_t));
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// create a context with RGBA pixels
CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
// paint the bitmap to our context which will fill in the pixels array
CGContextDrawImage(context, CGRectMake(0, 0, width, height), [img CGImage]);
//allocate pixels array
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
uint8_t *rgbaPixel1 = (uint8_t *) &pixels[y * width + x];
uint8_t *rgbaPixel2 = (uint8_t *) &pixels[y * width + x + 1];
//uint32_t color = r * rgbaPixel[RED] + g * rgbaPixel[GREEN] + b * rgbaPixel[BLUE];
// set the pixels to the color
rgbaPixel1[0] = (rgbaPixel1[0] + rgbaPixel2[0]/2);
rgbaPixel1[1] = (rgbaPixel1[1] + rgbaPixel2[1]/2);
rgbaPixel1[2] = (rgbaPixel1[2] + rgbaPixel2[2]/2);
rgbaPixel1[3] = 255;
}
}
但所有我得到的是一些有趣的結果!
有幫助嗎? 謝謝:)
鏈接列表並不是一個好的[SO]答案。請解釋鏈接中發生了什麼的細節,以便它成爲一個有用的答案。不僅需要點擊鏈接才能獲得答案,而且鏈接可能會在某個時候成爲死鏈接,不再是有用的答案,這不僅令人不快。 – Joe