[請益] 請問文字跟圖片整合問題

看板MacDev作者 (*****)時間11年前 (2013/06/13 23:58), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
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
文章代碼(AID): #1HkUmFSG (MacDev)