0

I have a png mask that looks like this

enter image description here

I want to be able to fill the inside of the subject also with black.

I think the easiest algorithm would be to trim all the transparent pixels outside the subject and then apply a solid background to the whole image. There might be other ways.

I was able to draw an outline of the subject with how to add colored border to uiimage in swift so I assume it should be possible to trim the outside pixels?

For example using the code above

Image(uiImage: UIImage(named: "outline")!.stroked())
                .resizable()
                .aspectRatio(contentMode: .fit)
                .background(.red)

I am able to accurately outline the subject enter image description here

But what I would need it the following final result:

enter image description here

erotsppa
  • 14,248
  • 33
  • 123
  • 181
  • You can do almost anything in iOS that you can with photoshop. But you must know what the process would be since there will be no manual photo editor which validates the result – Mojtaba Hosseini Jul 05 '23 at 21:29
  • @MojtabaHosseini can you provide solution for the fill in? – erotsppa Jul 05 '23 at 21:33
  • @MojtabaHosseini thank you friend, edited question. I was not able to use the answer from the other 2 bounty questions because turns out some shapes have holes in them :( any ideas? – erotsppa Jul 05 '23 at 21:45
  • Its very clear that you are using all of these for a single project but your questions are different and have different answers. Im sure you can overcome these if you Keep up trying – Mojtaba Hosseini Jul 05 '23 at 22:07
  • You can research for “connected components” to get started. Then just find connect white pixels of top left corner and color anything else – Mojtaba Hosseini Jul 05 '23 at 22:12
  • @erotsppa - Apple documentation: [Applying flood fills to an image](https://developer.apple.com/documentation/accelerate/vimage/vimage_operations/applying_a_flood_fill_to_an_image/applying_flood_fills_to_an_image) – DonMag Jul 12 '23 at 16:09

0 Answers0