署名を検出して png 形式で保存するアプリを作成したいと考えています。http://www.ifans.com/forums/threads/tutorial-drawing-to-the-screen.132024/の描画方法に関するリンクを見つけました 。しかし、pngファイルとして保存する方法がわかりません。誰かが描いた画像を保存する方法を教えてください。
1225 次
1 に答える
0
ビューのスクリーンショットを撮り、それをアプリのドキュメント ディレクトリに保存できます。
ビューのスクリーンショットを撮り、
CGRect rect = [yourView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[yourView.layer renderInContext:context];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
キャプチャscreenshot
したファイルをドキュメント ディレクトリに保存し、
NSString *documentsDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/myPngFile.png",documentsDirPath];
[UIImagePNGRepresentation(screenshot) writeToFile:pngFilePath atomically:YES];
それが役立つことを願っています!
于 2013-10-22T07:23:16.120 に答える