title: Swift - Compare colors at CGPoint
body: <p>I have 2 pictures which I want to compare, if pixel color is the same to save it.
  I detect the color of the pixel by this <code>UIImage</code> extension function:</p>
  
  <pre><code>func getPixelColor(pos: CGPoint) -&gt; ??? {
  
      let pixelData = CGDataProviderCopyData(CGImageGetDataProvider(self.CGImage))
      let data: UnsafePointer&lt;UInt8&gt; = CFDataGetBytePtr(pixelData)
  
      let pixelInfo: Int = ((Int(self.size.width) * Int(pos.y)) + Int(pos.x)) * 4
  
      let r = CGFloat(data[pixelInfo]) / CGFloat(255.0)
      let g = CGFloat(data[pixelInfo+1]) / CGFloat(255.0)
      let b = CGFloat(data[pixelInfo+2]) / CGFloat(255.0)
      let a = CGFloat(data[pixelInfo+3]) / CGFloat(255.0)
  
      return ???
  }
  </code></pre>
  
  <p>For example, I run the scanner on picture 1 and save it in an array? Or dictionary? And after that I run the scanner on picture 2 and when I have the information from 2 pictures to compare it with what function?</p>
  
  <p>I want to see on which CGPoint the pixels colors are identical from 2 images?</p>
  
  <p>UPDATE:
  I update getPixelColor to return me "(pos)(r)(g)(b)(a)" and after that I created this function which left only duplicates (BEFORE USING THIS FUNCTION YOU HAVE TO .sort() THE ARRAY!)</p>
  
  <pre><code>extension Array where Element : Equatable {
      var duplicates: [Element] {
          var arr:[Element] = []
          var start = 0
          var start2 = 1
          for _ in 0...self.count{
              if(start2&lt;self.count){
                  if(self[start] == self[start2]){
                      if(arr.contains(self[start])==false){
                          arr.append(self[start])
                      }
                  }
                  start+=1
                  start2+=1
              }
          }
          return arr
      }
  }
  </code></pre>
  
  <p>This returns me something like this:
  "(609.0, 47.0)1.01.01.01.0" I know that the color is black at this point I do x-536 to fit iPhone 5 screen and when I make an attempt to draw it again it draws something wrong... maybe I can't do it properly.. help?</p>