使用相机单击照片后,iPhone将照片存储在应用程序中

发布于 2024-10-18 08:20:48 字数 86 浏览 2 评论 0原文

我想通过应用程序使用相机单击照片。然后将照片存储在应用程序中。是否可以?谁能告诉我如何实现这一目标。我还想知道 .EXIF 数据是否会与图像一起保留。请帮忙。

I want to click photos using the camera through the application. then store the photo in the application. Is it possible? Can anyone Please tell me how this can be achieved. I also want to know if the .EXIF data will be retained along with the image.Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筑梦 2024-10-25 08:20:48

这个概念从应用程序和应用程序中获取屏幕截图。稍后使用它们

1.

    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();

    CGContextRef context = UIGraphicsGetCurrentContext();
    UIImageWriteToSavedPhotosAlbum(saveImage, self, @selector(image:didFinishSavingWithError:contextInfo:), &context);
    UIGraphicsEndImageContext();


    NSData *imageData = UIImagePNGRepresentation(saveImage);
    NSString *imageName = @"temp.png";

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];

    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
    [imageData writeToFile:fullPathToFile atomically:NO];

Above code takes screenshot of the view & save this image in the documentsDirectory as "temp.png"

2.

    NSInteger primaryKeyValue = 1;
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];
    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"temp.png"];
    NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat: @"%d.png",primaryKeyValue ]];
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    [fileMgr moveItemAtPath:fullPathToFile toPath:filePath2 error:nil];

3.
稍后,如果您想使用此图像

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *uniquePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat: @"%d.png",primaryKeyValue ]]; 
    UIImage *image = [UIImage imageWithContentsOfFile:uniquePath];  

This concept takes screenshot from the app & later using them

1.

    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();

    CGContextRef context = UIGraphicsGetCurrentContext();
    UIImageWriteToSavedPhotosAlbum(saveImage, self, @selector(image:didFinishSavingWithError:contextInfo:), &context);
    UIGraphicsEndImageContext();


    NSData *imageData = UIImagePNGRepresentation(saveImage);
    NSString *imageName = @"temp.png";

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];

    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
    [imageData writeToFile:fullPathToFile atomically:NO];

Above code takes screenshot of the view & save this image in the documentsDirectory as "temp.png"

2.

    NSInteger primaryKeyValue = 1;
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];
    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"temp.png"];
    NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat: @"%d.png",primaryKeyValue ]];
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    [fileMgr moveItemAtPath:fullPathToFile toPath:filePath2 error:nil];

3.
Later, if you want to use this image

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *uniquePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat: @"%d.png",primaryKeyValue ]]; 
    UIImage *image = [UIImage imageWithContentsOfFile:uniquePath];  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文