嗨,我正在使用此功能在图像上绘制完成后在图像上绘制文本,但是当我这样做时,它向我显示透明文本,即具有不透明度的文本,我不希望它应该是 alpha 1.0 我试图添加 fontcolor 属性使用 RGBA 但效果不错
-(UIImage*) drawText:(NSString*) text
inImage:(UIImage*) image
atPoint:(CGPoint) point
atSize :(CGSize) size
{
//[NSLog(@"Drawing Text on the Image : Text Posn x:%f y:%f ",point.x,point.y);
UIGraphicsBeginImageContext(_mainViewForDrawing.frame.size);
[image drawInRect:CGRectMake(_mainViewForDrawing.frame
.origin.x,_mainViewForDrawing.frame.origin.y,_mainViewForDrawing.frame.size.width,_mainViewForDrawing.frame.size.height)];
CGPoint pt;
pt.x = point.x + _camera2EditText.frame.size.width/2;
pt.y = point.y + _camera2EditText.frame.size.height/2;
UITextPosition *post = [_camera2EditText beginningOfDocument];
CGRect r = [_camera2EditText caretRectForPosition:post];
//[NSLog(@"Here is the rect: %f %f ",r.origin.x,r.origin.y);
CGRect rect = CGRectMake(r.origin.x, point.y + r.origin.y, _mainViewForDrawing.frame.size.width,_mainViewForDrawing.frame.size.height);
[[UIColor whiteColor] set];
//UIFont *font = [UIFont boldSystemFontOfSize:TextFontSize];
UIFont *font = [UIFont fontWithName:TEXT_FONT_NAME size:TEXT_FONT_SIZE];
if([text respondsToSelector:@selector(drawInRect:withAttributes:)])
{
//iOS 7
// NSDictionary *att = @{NSFontAttributeName:font};
NSDictionary *att = @{ NSFontAttributeName: font, NSForegroundColorAttributeName: [UIColor whiteColor]};
[text drawInRect:rect withAttributes:att];
}
else
{
//legacy support
[text drawInRect:CGRectIntegral(rect) withFont:font];
}
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
如何去做