我有这个代码返回CATextLayer放置在视频上,它返回模糊文本。我在网上搜索过,大多数人建议添加textLayer.contentsScale,但这对我没用。
- (CATextLayer *)buildTextLayerWithText:(NSString *)text atPosition:(WatermarkPosition)position forVideoSize:(CGSize)videoSize
{
CATextLayer *textLayer = [[CATextLayer alloc] init];
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
CGFloat fontSize = videoSize.height / 20.0;
[attributes setObject:(__bridge id)(__bridge CFTypeRef)([ChannelsInterface mediumFontOfSize:fontSize]) forKey:(NSString*)kCTFontAttributeName];
[attributes setObject:(__bridge id)[[UIColor whiteColor] CGColor] forKey:(NSString*)kCTForegroundColorAttributeName];
[attributes setObject:[NSNumber numberWithFloat:fontSize] forKey:(NSString*)kCTFontSizeAttribute];;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text attributes:attributes];
textLayer.string = attributedString;
CGSize textLayerSize = [text sizeWithAttributes:attributes];
textLayer.contentsScale = [UIScreen mainScreen].scale;
[textLayer setFrame:getFrameForPosition(textLayerSize, videoSize, position)];
textLayer.shadowColor = [UIColor blackColor].CGColor;
textLayer.shadowRadius = 1.0f;
textLayer.shadowOpacity = 0.5f;
textLayer.shadowOffset = CGSizeMake(0.0f, 0.0f);
[textLayer setRasterizationScale:[UIScreen mainScreen].scale];
[textLayer setShouldRasterize:YES];
return textLayer;
}