老实说,我甚至不抢RGB,你应该知道你把什么样的形象进入的UIImageView,所以计划基于这样的标签。
如果你必须选择RGB,那么这样做,事情是这样的:
UIGraphicsBeginImageContext(CGSizeMake(1,1));
let context = UIGraphicsGetCurrentContext()
//We translate in the opposite direction so that when we draw to the canvas, it will draw our point at the first spot in readable memory
CGContextTranslateCTM(context, -x, -y);
// Make the CALayer to draw in our "canvas".
self.layer.renderInContext(context!);
let colorpoint = UnsafeMutablePointer<UInt32>(CGBitmapContextGetData(context));
UIGraphicsEndImageContext();
其中X和Y是你想抓住点,自我是你的UIImageView。
编辑:@ Mr.T发布一个链接到如何做到这一点为好,如果你需要的平均,只是抓住改变UIGraphicsBeginImageContext(CGSizeMake(1,1));
到UIGraphicsBeginImageContext(CGSizeMake(width,height));
所需的像素量,并用这些数据计算平均
你应该更清楚!你需要平均颜色吗?或最上面的颜色?或颜色在哪里接触? –
http://stackoverflow.com/questions/12770181/how-to-get-the-pixel-color-on-touch –
对不起,如果我不清楚@T先生UILabel地区的平均颜色是需要什么。 (因此,例如,如果UILabel是50x10像素,则平均所需的区域也将与UIImageView完全相同的位置为50x10像素。)感谢您的链接,它指的是单个像素。我认为平均值会更强劲。任何有关完整而简单的Swift答案的建议。 – user4806509