Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:27:39+00:00 2026-06-18T09:27:39+00:00

I want to save an image with some metadata changes in a temp folder,

  • 0

I want to save an image with some metadata changes in a temp folder, without re-encoding the actual image data.

The only method that I found able to do this is ALAssetsLibrary/writeImageDataToSavedPhotosAlbum:metadata:completionBlock:, however, this one saves the image to the Photo Library. Instead, I want to save the image to a temp folder (for instance to share it by email, without populating the Photo Library).

I’ve tried using CGImageDestinationRef (CGImageDestinationAddImageFromSource), but it can only be created using a decoded image, which means it’s re-encoding it when saved (tested, pixel bytes look different).

Are there any other methods/classes available for iOS that can save image data along with metadata, besides using CGImageDestinationRef? Suggestions for workarounds would also be welcomed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:27:40+00:00Added an answer on June 18, 2026 at 9:27 am

    This is a frustrating problem with the iOS SDK. First, I recommend filing an enhancement request.

    Now, here is a potential workaround: IF the ALAsset was created by you (i.e., its editable property is YES) then you can basically read the data, write with metadata, read again, save to disk, and then write with the original metadata.

    This approach will avoid creating a duplicate image.

    Please read the // comments as I skipped some stuff for brevity (like building a metadata dictionary):

    ALAsset* asset; //get your asset, don't use this empty one
    if (asset.editable) {
    
        // get the source data
        ALAssetRepresentation *rep = [asset defaultRepresentation];
        Byte *buffer = (Byte*)malloc(rep.size);
        // add error checking here
        NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
        NSData *sourceData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
    
        // make your metadata whatever you want
        // you should use actual metadata, not a blank dictionary
        NSDictionary *metadataDictionary = [NSDictionary dictionary];
    
        // these are __weak to avoid creating an ARC retain cycle
        NSData __weak *originalData = sourceData;
        NSDictionary __weak *originalMetadata = [rep metadata];
    
        [asset setImageData:sourceData
                   metadata:metadataDictionary
            completionBlock:^(NSURL *assetURL, NSError *error) {
                //now get your data and write it to file
                if (!error) {
                    //get your data...
                    NSString *assetPath = [assetURL path];
                    NSData *targetData = [[NSFileManager defaultManager] contentsAtPath:assetPath];
    
                    //...write to file...
                    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                    NSString *documentPath = [searchPaths lastObject];
                    NSURL *fileURL = [NSURL fileURLWithPath:documentPath];
                    [targetData writeToURL:fileURL atomically:YES];
    
                    //...and put it back the way it was
                    [asset setImageData:originalData metadata:originalMetadata completionBlock:nil];
                } else {
                    // handle error on setting data
                    NSLog(@"ERROR: %@", [error localizedDescription]);
                }
            }];
    } else {
        // you'll need to make a new ALAsset which you have permission to edit and then try again
    
    }
    

    As you can see, if the ALAsset isn’t owned by you, you will need to create one, which will add a photo to the user’s library, which is exactly what you wanted to avoid. However, as you may have guessed, you cannot delete an ALAsset from the user’s photo library, even if your app created it. (Feel free to file another enhancement request for that.)

    So, if the photo/image was created in your app, this will work for you.

    But if not, it will create an additional copy the user must delete.

    The only alternative is to parse the NSData yourself, which would be a pain. There is no open-source library that I am aware of to fill this gap in the iOS SDK.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to save Image in Database with JSON web service .without image data
I want to save an image after some changes in image. but I am
i've got some binary data which i want to save as an image. When
I want to dynamically create some image from Java and save it to a
I want to save image from a url in assets folder. I can save
I want to save Image and some other information to databse in my asp.net
I want to save the application state that contains some UIcomponents as shown in
I have an image in an UIImageView and want to save it to the
I'm using 3d in WPF and want to save it to a 2d image
I want to extract first frame of uploaded video and save it as image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.