Software cropping (automatic cutting of transparent borders) image in objective-c / cocoa

Does anyone know how to crop an image (uiimage or cgimage). By cropping, I mean software cropping the opaque borders of an image. Therefore, if I have the image below:

  • 00111000
  • 00010000
  • 01011110
  • 00000000

this will give:

  • 011100
  • 001000
  • 101111
+5
source share
1 answer

Sum all rows and all columns of your image. In your example, you will get two arrays:

3 1 5 0
0 1 1 3 2 1 1 0

Then the first non-zero on the left and the last next to the right is where you should crop in each direction.

+4
source

All Articles