回答
UIImage *image1 = [UIImage imageNamed:@"image1.jpg"];
UIImage *image2 = [UIImage imageNamed:@"image2.jpg"];
CGSize newSize = image1.size; //set new size as you want
UIGraphicsBeginImageContext(newSize);
//crop image1
CGImageRef imageRef = CGImageCreateWithImageInRect([image1 CGImage], CGRectMake(0, 0, image1.size.width/2, image1.size.height));
image1 = [UIImage imageWithCGImage:imageRef scale:image1.scale orientation:image1.imageOrientation];
CGImageRelease(imageRef);
//crop image2
imageRef = CGImageCreateWithImageInRect([image2 CGImage], CGRectMake(0, 0, image2.size.width/2, image2.size.height));
image2 = [UIImage imageWithCGImage:imageRef scale:image2.scale orientation:image2.imageOrientation];
CGImageRelease(imageRef);
//combine both images
// Use existing opacity as is
[image1 drawInRect:CGRectMake(0, 0, newSize.width/2, newSize.height)];
// Apply supplied opacity if applicable
[image2 drawInRect:CGRectMake(newSize.width/2, 0, newSize.width/2, newSize.height) blendMode:kCGBlendModeNormal alpha:1];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *strPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true) objectAtIndex:0];
strPath = [strPath stringByAppendingPathComponent:@"img.png"];
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtPath:strPath error:&error];
NSData *imgdata = UIImagePNGRepresentation(newImage);
[imgdata writeToFile:strPath atomically:false];
NSLog(@"Path = %@",strPath); //on this path image will be stored
_View1.frame = CGRectMake(0, 0, Width/2, Width);
_View2.frame = CGRectMake(0, 0, Width/2, Width);
CAGradientLayer *gradientMask = [CAGradientLayer layer];
gradientMask.frame = self.View2.bounds;
gradientMask.colors = @[(id)[UIColor whiteColor].CGColor,
(id)[UIColor clearColor].CGColor];
gradientMask.startPoint = CGPointMake(0.5, 0.5); // start at left middle
gradientMask.endPoint = CGPointMake(0, 0.5); // end at right middle
self.View2.layer.mask = gradientMask;
就更簡單了,你可以使用一個CISwipeTransition
,並設置inputTime
0.5,
西蒙
我如何處理CISwipeTransition?你有什麼例子嗎? –
滑動轉換接受兩個圖像 - 「inputImage」和「inputTargetImage」。它主要是爲幻燈片放映等應用程序中的圖像之間的轉換而設計的,但通過將'inputTime'設置爲0.5,可以對兩幅圖像進行分屏顯示。恐怕我不會說ObjC,但我確實有一個Swift演示應用程序用於探索CI轉換:https://github.com/FlexMonkey/CoreImageTransitionExplorer –
沒錯。但我只需要調整圖像之間的混合漸變,我不需要過渡。之後我必須將這兩幅圖像繪製成一幅圖像。 –
如果你想使用核芯顯卡,您可以創建一個梯度面具,繪製的第一個映像,應用梯度剪貼蒙版,然後繪製第二圖像。因此,第一圖像是未截短的,第二個被限幅到梯度:
- (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;
}
導致:
- 1. photoshop如何將兩個圖像混合在一起?
- 2. photoshop如何將兩個圖像混合在一起?
- 3. 將兩個視頻混合在一起?
- 4. 將兩個模板混合在一起
- 5. 兩個圖像融合在一起
- 6. 將兩個圖像與乘法和不透明度混合在一起
- 7. 混合兩個CAF文件在一起
- 8. 將兩張圖片混合在一起java
- 9. 混合兩個圖像HTML5畫布
- 10. 如何混合兩個圖像
- 11. 使用pilimages混合兩個圖像
- 12. Alpha與兩個透明圖像混合
- 13. 將兩個音頻文件與python混合在一起
- 14. 將Haskell中的兩個列表隨機混合在一起
- 15. Git - 如何將兩個存儲庫混合在一起
- 16. 用pixastic混合兩個圖像不起作用。如何獲得新的圖像?
- 17. 試圖將兩個字符串混合在一起用於AD用戶名
- 18. 將一副紙牌與圖像混合
- 19. WriteableBitmapEx - 合併兩個圖像在一個
- 20. 將兩個指令結合在一起
- 21. 將兩個腳本結合在一起
- 22. 將兩個陣列組合在一起?
- 23. 將兩個數組合並在一起
- 24. 將兩個圖像合併爲一個新圖像
- 25. 將兩個圖像合併爲一個透明圖像
- 26. 使用.NET將兩個PNG圖像組合成一個圖像
- 27. 混合兩個圖像和從兩個的UIImageViews
- 28. ANTLR將INT與FLOAT混合在一起
- 29. PHP添加兩個圖像融合在一起
- 30. 通過Opencv混合兩幅圖像
本教程可以幫助https://www.raywenderlich.com/69855/image-processing-in-ios-part-1-raw-bitmap-modification –
如何使用Photoshop? –