开发者

How to set RGBA Color of a Pixel of an UIImage

开发者 https://www.devze.com 2023-04-07 03:51 出处:网络
I am looking for a possibility to set (change) the RGBA color of a Pixel of an UIImage for my Iphone Application. (I actually want to implement some f开发者_开发知识库loodfill stuff)

I am looking for a possibility to set (change) the RGBA color of a Pixel of an UIImage for my Iphone Application. (I actually want to implement some f开发者_开发知识库loodfill stuff)

So I need something like this:

-(void) setPixelColorOfImage: (UIImage*) img atXCord: (int) x atYCord: (int) y
withRedColor: (CGFloat) red blueColor: (CGFloat) blue greenColor: (CGFloat) green
alpha: (CGFloat) alpha  {

// need some code her

}

Because this method will be called quite often, it shouldn't be too slow.

Please help.


UIImage is not (externally) mutable, so you must copy, then edit, then convert to UIImage.

Copy

  • create a CGBitmapContext
  • draw the source image onto it

Edit

  • get a hold of the context's pixel buffer
  • mutate that pixel buffer

Convert to UIImage

  • copy a CGImage representation of the context
  • create a new UIImage from the CGImage

fwiw, the form can also be used on osx (using NSImage).

0

精彩评论

暂无评论...
验证码 换一张
取 消