0
A
回答
0
對於長期實現The你應該看看核心圖像框架tutorial。 對於一次性案例,你可以參考已有的答案iPhone : How to change color of particular pixel of a UIImage? 我發現了很好的非ARC解決方案,它可以改變整個幀內的圖片顏色,但是你可以嘗試採用它來僅應用於某個像素:
- (void) grayscale:(UIImage*) image {
CGContextRef ctx;
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
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.
int byteIndex = (bytesPerRow * 0) + 0 * bytesPerPixel;
for (int ii = 0 ; ii < width * height ; ++ii)
{
// Get color values to construct a UIColor
CGFloat red = (rawData[byteIndex] * 1.0)/255.0;
CGFloat green = (rawData[byteIndex + 1] * 1.0)/255.0;
CGFloat blue = (rawData[byteIndex + 2] * 1.0)/255.0;
CGFloat alpha = (rawData[byteIndex + 3] * 1.0)/255.0;
rawData[byteIndex] = (char) (red);
rawData[byteIndex+1] = (char) (green);
rawData[byteIndex+2] = (char) (blue);
byteIndex += 4;
}
ctx = CGBitmapContextCreate(rawData,
CGImageGetWidth(imageRef),
CGImageGetHeight(imageRef),
8,
CGImageGetBytesPerRow(imageRef),
CGImageGetColorSpace(imageRef),
kCGImageAlphaPremultipliedLast);
imageRef = CGBitmapContextCreateImage (ctx);
UIImage* rawImage = [UIImage imageWithCGImage:imageRef];
CGContextRelease(ctx);
self.workingImage = rawImage;
[self.imageView setImage:self.workingImage];
free(rawData);
}
來源:不同顏色的http://brandontreb.com/image-manipulation-retrieving-and-updating-pixel-values-for-a-uiimage
+0
第二個鏈接的代碼有錯誤,沒有編譯.. – 2014-12-04 05:59:20
+0
添加了一個更多的解決方案,可能被採納爲您的需求。 – 2014-12-04 10:57:39
相關問題
- 1. iPhone:如何更改UIImage特定像素的顏色?
- 2. 更改UIImage中的顏色
- 3. 更改圖像中的特定顏色
- 4. 如何在uiimage中更改單個像素的顏色
- 5. 無法更改UIImage中像素的顏色
- 6. 更改像素的顏色
- 7. 在java中掃描某個特定像素顏色的圖像
- 8. 如何改變位圖中某些像素的顏色android
- 9. Fullcalendar更改某些事件的顏色
- 10. 更改某些圖表點的顏色
- 11. 更改某些字符的顏色
- 12. 更改GdkPixbuf(GTK3)中像素的顏色
- 13. 將某些像素RGB顏色到另一種顏色
- 14. 獲取UIImage的像素顏色
- 15. 更改ImageIcon中的特定顏色
- 16. 將基於RBG值的UIImage中的特定像素更改爲不同的RBG顏色
- 17. 通過片段/像素着色器改變特定的像素顏色?(opengl)
- 18. 如何更改顏色條的顏色(在某個特定的值間隔內)?
- 19. 更改像素圖的顏色
- 20. 更改位圖的像素顏色
- 21. Android - 更改位圖的像素顏色
- 22. 如何更改UIImage部分的顏色?
- 23. 在MATLAB中給出像素位置的像素顏色更改
- 24. 如何更改特定行中所有select2元素的顏色
- 25. Android在更改圖像時更改了像素的顏色
- 26. Qt/PyQt(/其他?):如何更改像素圖中的特定顏色?
- 27. 更改像素顏色作爲其顏色的功能
- 28. 將UIWebView默認顏色更改爲UIImage
- 29. 更改特定字符串的顏色
- 30. 更改特定的行顏色uipicker
添加視圖,在您的ImageView – 2014-12-04 05:22:18
添加另一種觀點認爲不給我理所當然的樣子,我想這種變化看起來更自然的原始圖像。 – 2014-12-04 05:23:16
使用另一個imagview而不是視圖 – 2014-12-04 05:24:21