Ios 将两幅图像混合在一起
我正在尝试将两个图像合并到最终图像中,但不幸的是,我找不到这样做的方法。我如何合并两张照片,如下图所示Ios 将两幅图像混合在一起,ios,objective-c,core-image,Ios,Objective C,Core Image,我正在尝试将两个图像合并到最终图像中,但不幸的是,我找不到这样做的方法。我如何合并两张照片,如下图所示 更简单的是,您可以使用a并将输入时间设置为0.5 Simon更简单的是,您可以使用一个 Simon如果要使用Core Graphics,可以创建渐变遮罩,绘制第一幅图像,将渐变应用为剪裁遮罩,然后绘制第二幅图像。因此,第一个图像被取消剪辑,第二个图像被剪裁到渐变: - (UIImage *)imageCombiningImage:(UIImage *)image1 withImage:
更简单的是,您可以使用a并将
输入时间设置为0.5
Simon更简单的是,您可以使用一个
Simon如果要使用Core Graphics,可以创建渐变遮罩,绘制第一幅图像,将渐变应用为剪裁遮罩,然后绘制第二幅图像。因此,第一个图像被取消剪辑,第二个图像被剪裁到渐变:
- (UIImage *)imageCombiningImage:(UIImage *)image1 withImage:(UIImage *)image2 {
CGRect rect = CGRectMake(0, 0, image1.size.width, image1.size.height);
UIGraphicsBeginImageContextWithOptions(image1.size, TRUE, image1.scale);
// create gradient
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = { 0.45, 0.55 }; // gradient goes from 45% to 55% the way across the image
CGFloat components[] = {
1.0, 1.0, 1.0, 1.0, // Start color ... white
0.0, 0.0, 0.0, 0.0 // End color ... clear
};
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);
// create mask from that gradient
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(image1.size.width, 0), kCGGradientDrawsAfterEndLocation);
CGImageRef gradientImageRef = CGBitmapContextCreateImage(context);
// draw the first image
[image1 drawInRect:rect];
// clip subsequent drawing to the gradient mask we just created
CGContextClipToMask(context, rect, gradientImageRef);
// draw the second image
[image2 drawInRect:rect];
// extract the image
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// clean up
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);
CGImageRelease(gradientImageRef);
return combinedImage;
}
这导致:
如果要使用核心图形,可以创建渐变遮罩,绘制第一幅图像,将渐变应用为剪裁遮罩,然后绘制第二幅图像。因此,第一个图像被取消剪辑,第二个图像被剪裁到渐变:
- (UIImage *)imageCombiningImage:(UIImage *)image1 withImage:(UIImage *)image2 {
CGRect rect = CGRectMake(0, 0, image1.size.width, image1.size.height);
UIGraphicsBeginImageContextWithOptions(image1.size, TRUE, image1.scale);
// create gradient
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = { 0.45, 0.55 }; // gradient goes from 45% to 55% the way across the image
CGFloat components[] = {
1.0, 1.0, 1.0, 1.0, // Start color ... white
0.0, 0.0, 0.0, 0.0 // End color ... clear
};
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);
// create mask from that gradient
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(image1.size.width, 0), kCGGradientDrawsAfterEndLocation);
CGImageRef gradientImageRef = CGBitmapContextCreateImage(context);
// draw the first image
[image1 drawInRect:rect];
// clip subsequent drawing to the gradient mask we just created
CGContextClipToMask(context, rect, gradientImageRef);
// draw the second image
[image2 drawInRect:rect];
// extract the image
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// clean up
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);
CGImageRelease(gradientImageRef);
return combinedImage;
}
这导致:
本教程可能有助于如何使用Photoshop?本教程可能有助于如何使用Photoshop?感谢帮助@Richard G这显然不是渲染两幅图像之间的渐变过渡,而是一个硬过渡。感谢帮助@Richard G这显然不是渲染两幅图像之间的渐变过渡,但这是一个艰难的过渡。我如何处理这个过渡?您有什么例子吗?滑动转换接受两个图像-inputImage
和inputImage
。它主要设计用于在应用程序(如幻灯片放映)中的图像之间转换,但通过将inputTime
设置为0.5,它提供了两个图像的分屏视图。恐怕我不会说ObjC,但我有一个用于探索CI转换的快速演示应用程序:没错。但我只需要调整图像之间的混合梯度,我不需要过渡。之后,我必须将这两幅图像绘制成一幅图像。如何处理转换?您有什么例子吗?滑动转换接受两个图像-inputImage
和inputImage
。它主要设计用于在应用程序(如幻灯片放映)中的图像之间转换,但通过将inputTime
设置为0.5,它提供了两个图像的分屏视图。恐怕我不会说ObjC,但我有一个用于探索CI转换的快速演示应用程序:没错。但我只需要调整图像之间的混合梯度,我不需要过渡。之后,我必须把这两个图像画成一个图像。
- (UIImage *)imageCombiningImage:(UIImage *)image1 withImage:(UIImage *)image2 {
CGRect rect = CGRectMake(0, 0, image1.size.width, image1.size.height);
UIGraphicsBeginImageContextWithOptions(image1.size, TRUE, image1.scale);
// create gradient
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = { 0.45, 0.55 }; // gradient goes from 45% to 55% the way across the image
CGFloat components[] = {
1.0, 1.0, 1.0, 1.0, // Start color ... white
0.0, 0.0, 0.0, 0.0 // End color ... clear
};
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);
// create mask from that gradient
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(image1.size.width, 0), kCGGradientDrawsAfterEndLocation);
CGImageRef gradientImageRef = CGBitmapContextCreateImage(context);
// draw the first image
[image1 drawInRect:rect];
// clip subsequent drawing to the gradient mask we just created
CGContextClipToMask(context, rect, gradientImageRef);
// draw the second image
[image2 drawInRect:rect];
// extract the image
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// clean up
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);
CGImageRelease(gradientImageRef);
return combinedImage;
}