gpt4 book ai didi

ios - 在ios中以png格式保存签名图片

转载 作者:行者123 更新时间:2023-11-29 12:00:58 25 4
gpt4 key购买 nike

我有用于签名的可绘制文本,我希望此上下文以具有特定路径的 png 格式保存,但我不能这样做。我希望我的绘图图像以 png 格式保存,我可以在任何地方使用

**Code for png format and path**

NSData *imageData = UIImagePNGRepresentation(_SignatureView.signatureImage);

NSString *imagePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"/imageName.png"];

[imageData writeToFile:imagePath atomically:YES];

_SignatureView is a property and signatureImage is a method

**code of signature image method**

- (UIImage *)signatureImage
{
if (!self.hasSignature)
return nil;


UIImage *screenshot = [self snapshot];


return screenshot;
}

最佳答案

NSString *docPath=  @"/Users/.../.../";
NSString *filePath=[docPath stringByAppendingPathComponent:@"PdfFileName.pdf"];

NSMutableData pdfData=[NSMutableData data];
CGRect bounds = CGRectMake(0, 0, 612, 792);
UIGraphicsBeginPDFContextToData(pdfData, bounds, nil);

CGContextRef pdfContext = UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPage();

[YourSignature.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
[pdfData writeToFile:filePath atomically:YES];

关于ios - 在ios中以png格式保存签名图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37020598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com