我想從圖像1複製到圖像2像素,並保存圖像1中的數據字典:[UIColor:CGPoint]
。從字典中逐個像素地從一個圖像繪製到另一個以相同的座標
如何在CGContext上繪製所有的像素點,並且圖像2上的某個像素在同一個CGPoint上的確切顏色?
@IBAction func save(sender: UIButton) {
UIGraphicsBeginImageContext(CGSizeMake(100, 50))
let context = UIGraphicsGetCurrentContext()
for (color,point) in dict{
drawPixel(context!, startPoint: point, color: color.CGColor)
}
testIV.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
func drawPixel(context:CGContextRef, startPoint:CGPoint, color:CGColorRef){
dispatch_async(dispatch_get_main_queue(), {
CGContextSaveGState(context)
CGContextSetLineCap(context, .Square)
CGContextBeginPath(context)
CGContextSetStrokeColorWithColor(context, color)
CGContextSetLineWidth(context, 1.0)
CGContextMoveToPoint(context, startPoint.x + 0.5, startPoint.y + 0.5)
CGContextAddLineToPoint(context, startPoint.x + 0.5, startPoint.y + 0.5)
CGContextStrokePath(context)
CGContextRestoreGState(context)
})
}
我已經試過這樣,但圖像是空的...
你嘗試過這麼遠嗎?顯示你自己的一些代碼,你想繪製的地方。 – luk2302
我已經複製了照片中的像素,我想在同一個地方的另一張照片上繪製它 –
是的,您對繪圖有什麼想法? – luk2302