Quartz: image acquisition of two images

I follow two images, the background may be a completely different image, for example. not just color.

Image number oneenter image description here

So basically I want to get a diff image of these two images, i.e.

enter image description here

A differential image of two images is an image with the same size, but the pixels are set to transparent, which have not been resized. The difference image is constructed from diff pixels with color from the second image.

I am looking for a solution based on Core Graphics technologies, please do not offer to run all the pixels in a loop. I care about performance.

Since I'm new to Quartz, I would like to know if this can be achieved with masks? Or try a different approach!

, , , . 2 ,

enter image description here

, , , , ,

enter image description here

, ,

+5
2

Core Graphics

CGContextSetBlendMode(kCGBlendModeDifference);

, , ( ). ( ). , ( "" ).

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);
+6

All Articles