private void SaveImageToCameraRoll(Stream stream, MemoryStream thumbStream) { string fileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff") + "#" + m_sequenceGuid.ToString(); ExifFile exif = ExifFile.ReadStream(stream); string metadata = GetMetadata(fileName); byte[] data = Encoding.UTF8.GetBytes(metadata); uint length = (uint)data.Length; ushort type = 2; var imgDescProp = ExifPropertyFactory.Get(0x010e, type, length, data, BitConverterEx.ByteOrder.BigEndian, IFD.Zeroth); exif.Properties.Add(ExifTag.ImageDescription, imgDescProp); using (var ml = new MediaLibrary()) { exif.SaveToCameraRoll("mapi_" + fileName + ".jpg", ml); using (var memstream = new MemoryStream()) { WriteableBitmap bmp = new WriteableBitmap(100, 75); bmp = bmp.FromStream(thumbStream); WriteableBitmap tBmp = bmp.Resize(100, 75, WriteableBitmapExtensions.Interpolation.NearestNeighbor); tBmp.SaveJpeg(memstream, 100, 75, 0, 90); memstream.Seek(0, SeekOrigin.Begin); ml.SavePictureToCameraRoll("mapi_thumb_" + fileName + ".jpg", memstream); } } stream.Close(); thumbStream.Close(); stream.Dispose(); thumbStream.Dispose(); }
private async Task ExifTest() { using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { var folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("shared\\transfers"); var images = await folder.GetFilesAsync(); var first = images.FirstOrDefault(); if (first == null) { return; } using (IsolatedStorageFileStream stream = storage.OpenFile(@"shared\\transfers\" + first.Name, FileMode.Open)) { ExifFile exif = ExifFile.ReadStream(stream); } } }
private void SaveImageToIsoStore(Stream stream, MemoryStream thumbStream) { string fileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff") + "#" + m_sequenceGuid.ToString(); ExifFile exif = ExifFile.ReadStream(stream); string metadata = GetMetadata(fileName); byte[] data = Encoding.UTF8.GetBytes(metadata); uint length = (uint)data.Length; ushort type = 2; var imgDescProp = ExifPropertyFactory.Get(0x010e, type, length, data, BitConverterEx.ByteOrder.BigEndian, IFD.Zeroth); exif.Properties.Add(ExifTag.ImageDescription, imgDescProp); using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isStore.DirectoryExists("shared")) { isStore.CreateDirectory("shared"); } if (!isStore.DirectoryExists("shared\\transfers")) { isStore.CreateDirectory("shared\\transfers"); } using (IsolatedStorageFileStream targetStream = isStore.OpenFile(@"shared\\transfers\" + fileName + ".jpg", FileMode.Create, FileAccess.Write)) { exif.SaveStream(targetStream); } using (IsolatedStorageFileStream thumbtargetStream = isStore.OpenFile(@"shared\\transfers\thumb_" + fileName + ".jpg", FileMode.Create, FileAccess.Write)) { WriteableBitmap bmp = new WriteableBitmap(100, 75); bmp = bmp.FromStream(thumbStream); WriteableBitmap tBmp = bmp.Resize(100, 75, WriteableBitmapExtensions.Interpolation.NearestNeighbor); tBmp.SaveJpeg(thumbtargetStream, 100, 75, 0, 90); } stream.Close(); thumbStream.Close(); stream.Dispose(); thumbStream.Dispose(); } }
private void rotateBtn_Click(object sender, RoutedEventArgs e) { previewImage.Source = null; if (m_selectedFile != null) { Dictionary <ExifTag, ExifProperty> exifProperties = new Dictionary <ExifTag, ExifProperty>(); using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { WriteableBitmap bmp = new WriteableBitmap(0, 0); string exifData = null; using (var fileStream = storage.OpenFile(m_selectedFile.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { ExifFile exif = ExifFile.ReadStream(fileStream); var data = exif.Properties[ExifTag.ImageDescription]; exifData = (string)data.Value; fileStream.Close(); } using (var fileStream = storage.OpenFile(m_selectedFile.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { bmp = bmp.FromStream(fileStream); bmp = bmp.Rotate(90); fileStream.Close(); } lock (readLock) { using (IsolatedStorageFileStream stream = storage.CreateFile(@"shared\\transfers\" + m_selectedFile.Name)) { bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 98); stream.Close(); } } ExifFile exifRotated; using (var fileStream = storage.OpenFile(m_selectedFile.Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { exifRotated = ExifFile.ReadStream(fileStream); fileStream.Close(); byte[] data = Encoding.UTF8.GetBytes(exifData); uint length = (uint)data.Length; ushort type = 2; var imgDescProp = ExifPropertyFactory.Get(0x010e, type, length, data, BitConverterEx.ByteOrder.BigEndian, IFD.Zeroth); exifRotated.Properties.Add(ExifTag.ImageDescription, imgDescProp); } lock (readLock) { using (IsolatedStorageFileStream targetStream = storage.OpenFile(m_selectedFile.Path, FileMode.Create, FileAccess.Write, FileShare.None)) { exifRotated.SaveStream(targetStream); targetStream.Close(); } } previewImage.Source = bmp; } } if (m_selectedThumbFile != null) { using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { var bmp = new WriteableBitmap(0, 0); bool exist = storage.FileExists(m_selectedThumbFile.Path); if (exist) { using (var fileStream = storage.OpenFile(m_selectedThumbFile.Path, FileMode.Open, FileAccess.Read, FileShare.None)) { bmp = bmp.FromStream(fileStream); bmp = bmp.Rotate(90); fileStream.Close(); } lock (readLock) { using (IsolatedStorageFileStream stream = storage.CreateFile(@"shared\\transfers\" + m_selectedThumbFile.Name)) { bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 98); stream.Close(); } } viewModel.PhotoList[m_selectionIndex - 1].ImageSource = new BitmapImage(new Uri(m_selectedThumbFile.Path)) { CreateOptions = BitmapCreateOptions.IgnoreImageCache }; } } } }