[請益] 請問文字跟圖片整合問題
Dear 各位高手
不知有人有用過將文字的字串跟圖片合成,
然後成為另一個圖片有合成文字的功能嗎,
我有試著用如下的code, 英文可以,但是中文會出現亂碼
主要原因是編碼好像沒有支援中文,不知有人有解過這個問題嗎
請多指教,code如下:
//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:NSUTF8StringEncoding];// "05/05/09";
CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 255, 255, 255, 1);
CGContextShowTextAtPoint(context, 4, 10, text, strlen(text));
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.163.83.225