Save Exif data to Image inside Documents folder on iOS device - ios

I have UIImage *photoImage containing jpg file. I would like to add EXIF data to this image like UserComment, ImageDescription and Software. I would like to save this file to Documents folder on my iOS device as myImage.jpg I don't want to save it to PhotoLibrary.
I am not sure how to add EXIF data.
I would save image to disk by using
NSData *photoData = UIImageJPEGRepresentation(photoImage, 1);
[photoData writeToFile:filePath atomically:YES];
How do I add EXIF data to photoData? Thanks

Related

How to add an image in a CSV file

I am writing an XCUItest and taking a screenshot of the final screen. I am saving all the result in a CSV file. Using Jenkins I am sending that CSV file as a mail.
How can I add the screenshot in my CSV file, right now I have saved the screenshot in my local device but not able to save it in a CSV file?
XCUIScreenshot* Screenshot = XCUIScreen.mainScreen.screenshot;
UIImage *image = Screenshot.image;
NSData* imageData = UIImagePNGRepresentation(image);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *myImageData = UIImagePNGRepresentation(image);
[fileManager createFileAtPath:#"filelocation/myimage.png" contents:myImageData attributes:nil];
There is no way you can send the image in csv file. So you can change your approach by storing the screen shots (may be for few days) on web server and send the url of image as value in CSV or Alternately, as multiple attachments to the email with image file names as references in CSV

How to fetch an image from photo library of iOS using URL path?

I used UIImagePickerController to select an image from photo library of an iOS device. Then I saved the URL path of the selected image in database using Core Data. Now I want to use that saved URL path to fetch the image in another view controller. How can I fetch the image using URL path using Objective-C? Is there any framework for that? I found ALAssets framework is deprecated.
You should not save the URL for the image, unless you saved it into a more permanent location on the device. UIImagePickerController will provide you a URL to a temporary image, but this may be deleted after you close the app.
Instead, grab the actual UIImage locally and save that as a blob with CoreData.
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
let imageData = UIImageJPEGRepresentation(image, 1.0)
From here, save the data as a blob to a CoreData database. This is an article in itself, so I won't go into depth here. Refer to a resource such as http://pinkstone.co.uk/how-to-save-a-uiimage-in-core-data-and-retrieve-it/
To retrieve that image from the data, fetch the blob from CoreData and convert it to a UIImage:
let imageData = < Core Data Fetch and Processing >
if let image = UIImage(data: imageData) {
// Use your image
}

Swift 3 : Download image and save it with name to Photo library [duplicate]

I have an iOS application where I am saving an image to my photos folder to my iPad. However, what I would like to do is store the image with a custom name (e.g. using the date and time stamp for when the image was actually captured), so that it would be easier for it to be retrieved in the future.
My code at the moment for storing my images is as follows:
- (IBAction)imageCapture:(id)sender {
UIImage *myImage = [_imageView currentImage];
UIImageWriteToSavedPhotosAlbum(myImage, nil, nil, nil);
}
I am able to store my image, but how do I name the image prior to storing it (e.g. "082620131100am.png"?
Since you cannot override any image/video in the user's photo library, you will not be able to give the the file a specific filename.
You can add some metadata to your image if you use the method: writeImageDataToSavedPhotosAlbum:metadata:completionBlock:, but you will not be able to set the filename.

How would I go about saving snaps (UIImage) to the sandbox?

I'm creating a Theos tweak for my jailbroken iPhone and I'm stuck on a feature. So far I can block screenshot detection and replay detection, add infinite text, and have the app open directly to the feed. The feature I'm stuck on is saving incoming and outgoing snaps (and stories, but one step at a time). I used the FLEXible tweak from Cydia to assist me and I noticed that the snaps have something to do with "UIImage." From what I know I have to somehow convert this UIImage to *.jpg or *.png and save it somewhere (I'm looking to save it to the app's Documents directory).
I searched around the site and found the following that may be helpful:
// Convert UIImage to JPEG
NSData *imgData = UIImageJPEGRepresentation(image, 1); // 1 is compression quality
// Identify the home directory and file name
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Test.jpg"];
// Write the file. Choose YES atomically to enforce an all or none write. Use the NO flag if partially written files are okay which can occur in cases of corruption
[imgData writeToFile:jpgPath atomically:YES];
and
// Create paths to output images
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Test.png"];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Test.jpg"];
// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
// Write image to PNG
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
(like I said I found this; it is not my code).
Bah, I'm not sure how I would incorporate this. Any help?

get image metadata without decoding image data (iOS)

I have an image file in my app directory. This is not encoded with the iOS default encoder but our own encoders.
The format can be JPEG (EXIF) or TIFF. They have been checked for compliancy with standards so for this post, we can treat it as any image.
I want to get metadata of the image but don't want to decode it. I have been suggested:
CGImageSourceRef imageSourceRef = CGImageSourceCreateWithData((__bridge_retained CFDataRef)(localImageData), nil);
CFDictionaryRef cfMetadata = CGImageSourceCopyPropertiesAtIndex(imageSourceRef, 0, nil);
NSDictionary *metaDataDic = [NSDictionary dictionaryWithDictionary:(__bridge_transfer NSDictionary *)(cfMetadata)];
What I want to know is 'does this decode the image?'
I know there is an incremental option which is used when transferring images to server. Is there a way to stop the decoding after it gets the EXIF info?

Resources