CGContextSetBlendMode(kCGBlendModeDifference);
最初の画像を描画し、ブレンドモードを差異に設定して2番目の画像を描画すると、私のコメントで示唆したように違いが得られます。これは、(あなたのアップデートの質問に見られるように)反転画像を与えます。イメージを反転するには、(ブレンドモードが "差"に設定されているため)同じ矩形を白色で塗りつぶすことができます。
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, frame);
サンプルコードは、すべてこれは(:)のdrawRect内の以下に見られることができません。
CGContextRef context = UIGraphicsGetCurrentContext();
// Your two images
CGImageRef img1 = [[UIImage imageNamed:@"Ygsvt.png"] CGImage];
CGImageRef img2 = [[UIImage imageNamed:@"ay5DB.png"] CGImage];
// Some arbitrary frame
CGRect frame = CGRectMake(30, 30, 100, 100);
// Invert the coordinates to not draw upside down
CGContextTranslateCTM(context, 0, frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// Draw original image
CGContextDrawImage(context, frame, img1);
// Draw the second image using difference blend more over the first
CGContextSetBlendMode(context, kCGBlendModeDifference);
CGContextDrawImage(context, frame, img2);
// Fill the same rect with white color to invert
// (still difference blend mode)
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, frame);
でhttp答えを受け入れ://stackoverflow.com/questions/3901404/create-a-mask-from-difference-between-two-images-iphoneが役立つようです。 –
リンクのための@rokjarcありがとうございますが、違いのブレンドモードは私の場合の解決策ではありません。 – deimus
'CGContextSetBlendMode(kCGBlendModeDifference);を設定した後にもう一方のイメージを描画するとどうなりますか? –