ユーザーが入力したテキストをobjective-cを介して.PNGファイルとして保存する必要があるプロジェクトに取り組んでいます。つまり、ユーザーがテキストを入力したときに、フォントタイプを選択して保存するオプションをユーザーに提供します。その後、ファイルはバックグラウンドなしで.PNGファイルとして保存されます。
どうすればこれを達成できますか。あなたの意見を共有してください。
前もって感謝します
ユーザーが入力したテキストをobjective-cを介して.PNGファイルとして保存する必要があるプロジェクトに取り組んでいます。つまり、ユーザーがテキストを入力したときに、フォントタイプを選択して保存するオプションをユーザーに提供します。その後、ファイルはバックグラウンドなしで.PNGファイルとして保存されます。
どうすればこれを達成できますか。あなたの意見を共有してください。
前もって感謝します
このメソッドを使用して、テキストから画像を取得します。
-(UIImage *)imageFromText:(NSString *)text
{
// set the font type and size
//UIFont *font = [UIFont systemFontOfSize:txtView.font];
CGSize size = [text sizeWithFont:txtView.font]; // label or textview
// check if UIGraphicsBeginImageContextWithOptions is available (iOS is 4.0+)
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions(size,NO,0.0);
else
// iOS is < 4.0
UIGraphicsBeginImageContext(size);
[text drawInRect:CGRectMake(0,0,size.width,size.height) withFont:txtView.font];
UIImage *testImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return testImg;
}
今、あなたはこのように画像を保存しています
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir]; // any name u want for image
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)]; your image here
[data1 writeToFile:pngFilePath atomically:YES];