在图像视图图像上写文本 [英] write text on image view image
本文介绍了在图像视图图像上写文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我正在开发一个应用程序,其中我有一个图像视图,其中图像经常
Currently, I am developing an App in which I have a Image view on which image are constantly
一段时间后发生变化。现在我希望我能够写一些文字或绘制任何符号
changes after some time. Now I want that I am able to write some text or draw any symbol
,简单的线条,十字线意味着说图像在图像视图中出现。意思是我想要
,simple line,cross line means to say drawing on image appears in image view. Means I want to
在图像上添加文字或绘制一些符号或线条e.t.c。我到处搜索但不能
add text or drawing some symbols or lines e.t.c on image. I am searching everywhere but can't
找到任何解决方案。我怎么解决这个问题?在此先感谢。
find any solution. How can I solve this? Thanks in advance.
推荐答案
看看是否有效:
//Add text to UIImage
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1{
int w = img.size.width;
int h = img.size.height;
//lon = h - lon;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];// "05/05/09";
CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 255, 255, 255, 1);
//rotate text
CGContextSetTextMatrix(context, CGAffineTransformMakeRotation( -M_PI/4 ));
CGContextShowTextAtPoint(context, 4, 52, text, strlen(text));
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
这篇关于在图像视图图像上写文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文