1

In my iOS app I have an image, that the user can touch and draw a path on it. I store all the touch (move) points in an array and then, when the path closed, I draw the path on the image. This works. Now, when the user touches (long press) this part of image, I want to copy it and make a new image from it.

How can I copy only that part of image? (as shown in the attached picture)

Thanks.

enter image description here

suyama
  • 262
  • 2
  • 15

1 Answers1

2

I would recommend you to firstly se the margin of the copy. This could be set by defining a square between the most left pixel and the most right one (horizontal dimension) and the same between the upper and the lower pixel (vertical dimension).

Then you can get the RGB information between this pixels and store in a new matrix.

  • For the pixels inside the path you can pick the RGB information by using the code here: https://stackoverflow.com/a/1262893/3057234
  • For the pixels outside the path, you can set them to a random color and put alpha value to 0.0.

Then you can reconvert this matrix to a UIImage, or perform the process you want.

Community
  • 1
  • 1
CRoig
  • 691
  • 5
  • 24