Can I edit the pixels of the UIImage's property CGImage

前端 未结 7 1441
野趣味
野趣味 2020-11-28 05:04

UIImage has a read-only property CGImage. I have to read its pixels to a memory block and edit them and then make a new UIImage to replace the old one. I want to know if th

7条回答
  •  渐次进展
    2020-11-28 05:21

    @shaun Inman's post has been the only working i've found on the web so far! THANK YOU! However it seems like at least in IOS3 the PNG colors are saved a bit different to what you stated, this is what worked for me (only for PNG!):

    for(int i = 0; i < [data length]; i += 4) {
        pixels[i+0]   = 0; // eg. alpha?
        pixels[i+1]   = 0; // eg. red!
        pixels[i+2]   = 0; // eg. green!
        pixels[i+3]   = pixels[i+3]; // eg. blue!
    }
    

    Would be cool if someone could figure out a way that worked for any filetype!

提交回复
热议问题