添加叠加后,UIImage周围会出现略微透明的白线?

时间:2011-06-03 03:34:26

标签: objective-c uiimage

我有一个将图像叠加在另一个图像上并作为UIImage返回的功能。但是,它出现了白线。这就是我所拥有的

- (UIImage * ) romanticFilterImage: (UIImage *) imageA {

UIImage *vintageOne = [UIImage imageNamed:@"filter_vintage_1.png"];
UIImage *vintageTwo= [UIImage imageNamed:@"filter_vintage_2.png"];
UIImage *vintageThree = [UIImage imageNamed:@"filter_vintage_3.png"];

UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageA.size.width, imageA.size.height), YES, 0.0); 
[imageA drawAtPoint: CGPointMake(0,0)];
[vintageThree drawInRect:CGRectMake(0, 0, imageA.size.width, imageA.size.height)  blendMode: kCGBlendModeMultiply alpha: 1.0];
[vintageTwo drawInRect:CGRectMake(0, 0, imageA.size.width + 2, imageA.size.height + 2)  blendMode: kCGBlendModeColorBurn alpha: 1.0];
[vintageOne drawInRect:CGRectMake(0, 0, imageA.size.width, imageA.size.height)  blendMode: kCGBlendModeMultiply alpha: 1.0];
UIImage *source = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();

CGSize size = [source size];
UIGraphicsBeginImageContext(size);
CGRect rect = CGRectMake(0, 0, size.width, size.height);
[source drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 5.0, 5.0, 5.0, 5.0); 
CGContextStrokeRect(context, rect);
UIImage *testImg =  UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return testImg;

}

以下是截图:(我添加了黑色背景以增强透明边框。

White border!

1 个答案:

答案 0 :(得分:3)

你不是在这些线条中将图像抚摸成白色吗?

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 5.0, 5.0, 5.0, 5.0); 
CGContextStrokeRect(context, rect);
UIImage *testImg =  UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

虽然我不确定您是否打算GContextSetRGBStrokeColor(context, 5.0, 5.0, 5.0, 5.0); 1.0rgba值是函数中{{1}}值的最大值。