Does anyone know how to trim an image (uiimage or cgimage). By trim I mean programatica开发者_JAVA技巧lly cropping to the non-transparent bounds of an image. So if I have the image below:
- 00111000
- 00010000
- 01011110
- 00000000
it would yield:
- 011100
- 001000
- 101111
Sum all rows and all columns of your image. You'll get two arrays, in your example looking like this:
3 1 5 0
0 1 1 3 2 1 1 0
Then the first non-zero from the left and the last one near the right is where you have to crop, in each direction.
精彩评论