dinchy87
dinchy87

Reputation: 169

Changing the Creation date in a picture while creating it with StorageFile

Im using a Storagefile to create a picture in the Windows Phone 8.1 saved pictures album in the photos gallery and so far this work ok. I use a stream from a picture that i save to this new picture, below you will see the code snippet. My problem is that the newly created picture has the creation date of the stream (source file), how can i change the new file creation date to DateTime.Now?!

here is how i save the picture:

    var pictureURL = "ms-appx:///Assets/folder/Picture.jpg";

    StorageFile storageFile = await KnownFolders.SavedPictures.CreateFileAsync("Picture.jpg", CreationCollisionOption.GenerateUniqueName);

    StorageFile pictureFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(pictureURL));

    using (var imageFile = await pictureFile.OpenStreamForReadAsync())
    {
            using (var imageDestination = await storageFile.OpenStreamForWriteAsync())
            {
                 await imageFile.CopyToAsync(imageDestination);
            }
    }

The above snippet makes a new picture called "storageFile" as you see, then get the file from the Application Uri thats the "pictureFile". then via using opens the source Picture for read as Stream, in this using another using statement opens the newly created picture file in the gallery for write, inside it the opened files data get copied to the destination file data and saved.

This works and the file is in the gallery but the creation time is from the source picture. How can i on runtime add the new creation time to it?!

Upvotes: 1

Views: 852

Answers (1)

dinchy87
dinchy87

Reputation: 169

This is the solution:

i Have found ImeProperties in the Windows.Storage.FileProperties and with the edited code below you can save the picture and right after it change the EXIF data like Date Taken and Camera Manufacturer and other details.

    var pictureURL = "ms-appx:///Assets/folder/Picture.jpg";

    StorageFile storageFile = await KnownFolders.SavedPictures.CreateFileAsync("Picture.jpg", CreationCollisionOption.GenerateUniqueName);

    StorageFile pictureFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(pictureURL));

    using (var imageFile = await pictureFile.OpenStreamForReadAsync())
    {
        using (var imageDestination = await storageFile.OpenStreamForWriteAsync())
        {
             await imageFile.CopyToAsync(imageDestination);
        }
    }

    ImageProperties imageProperties = await storageFile.Properties.GetImagePropertiesAsync();

    imageProperties.DateTaken = DateTime.Now;
    imageProperties.CameraManufacturer = "";
    imageProperties.CameraModel = "";

    await imageProperties.SavePropertiesAsync();

This will overwrite the existing data and this is what i was searching for.

Upvotes: 1

Related Questions