2 starwar2012 starwar2012 于 2013.05.02 16:42 提问

ios将文本标签放到照片中

我想要将当前的位置信息放到iPhone的照片上,不知道怎么实现?

位置信息已经获取了,就是不知道怎么通过文本信息来编辑照片。

谢谢您的帮忙。

3个回答

Kill_it
Kill_it   2013.05.02 17:36
已采纳

这是一段将文本放上照片的代码:

-(UIImage*) getImageWithText:(UIImage*) sourceImage
    {
        UIGraphicsBeginImageContext(sourceImage.size);
        [sourceImage drawAtPoint:CGPointZero];
    [@"someText" drawAtPoint:CGPointMake(x,y) [UIFont systemFontOfSize:14]]
    UIImage* imageWithText = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return imageWithText;
    }
ce_la_vie
ce_la_vie   2013.05.02 17:33

你可以这样实现:

//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];

}

qq_27687837
qq_27687837   2015.04.24 21:24

//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];
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!