/// <summary> /// Save the primitive image and thumbnail image and return the Photo model with local url /// </summary> /// <param name="imageBuffer"></param> /// <returns></returns> public static async Task<Photo> SaveImage(IBuffer imageBuffer) { try { Photo photo = new Photo { CreatedTime = DateTime.UtcNow }; AutoResizeConfiguration tbRC = null; AutoResizeConfiguration pvRC = null; Rect thumbnailRect; Size pvSize; using (var source = new BufferImageSource(imageBuffer)) { var info = await source.GetInfoAsync(); //var thumbnailSize = ImageHelper.CalculateSize(info.ImageSize); thumbnailRect = CalculateRect(info.ImageSize); pvSize = CalculateSize(info.ImageSize); tbRC = new AutoResizeConfiguration(ImageHelper.thumbnailMaxBytes, thumbnailMaxSize, new Size(0, 0), AutoResizeMode.Automatic, 0, ColorSpace.Yuv420); pvRC = new AutoResizeConfiguration(ImageHelper.pvMaxBytes, pvSize, new Size(0, 0), AutoResizeMode.Automatic, 0, ColorSpace.Yuv420); } using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { //Get LocalPath var localPath = AppResources.LocalImagePath; if (!store.DirectoryExists(localPath)) { store.CreateDirectory(localPath); } //Save the primitive bitmap file using (var file = store.CreateFile(photo.LocalUri = localPath + @"\" + photo.Tag + @"_Raw")) { using (var localImage = imageBuffer.AsStream()) { localImage.CopyTo(file); file.Flush(); localImage.Close(); } } //Save Preview Image if (pvRC != null) { //Resize the Image to priview image var pvBuffer = await Nokia.Graphics.Imaging.JpegTools.AutoResizeAsync(imageBuffer, pvRC); //Save Preview Image using (var file = store.CreateFile(localPath + @"\" + photo.Tag + @"_Preview.jpg")) { photo.PreviewDetailUri = file.Name; ; using (var localImage = pvBuffer.AsStream()) { localImage.CopyTo(file); file.Flush(); localImage.Close(); } } } //Save thumbnail Image if(tbRC != null) { //Crop to the square var rb = await Reframe(imageBuffer, thumbnailRect); //Resize the Image to thumbnail var tb = await Nokia.Graphics.Imaging.JpegTools.AutoResizeAsync(rb, tbRC); //Save thumbnail using (var file = store.CreateFile(photo.LocalThumbnailUri = localPath + @"\" + photo.Tag + @"_Thumbnail.jpg")) { photo.ThumbnailDetailUri = file.Name; using (var localImage = tb.AsStream()) { localImage.CopyTo(file); file.Flush(); localImage.Close(); } } } } return photo; } catch (Exception ex) { throw ex; } }
public bool RemovePhoto(Photo p) { return _imageList.Remove(p); }
public void AddPhoto(Photo p) { _imageList.Add(p); }
/// <summary> /// 将拍摄的照片添加到照片列表中 /// </summary> /// <param name="photo"></param> public void AddPhotoToList(Photo photo) { photo.ExtensionField1 = _photoType; _imageDataDic[_photoListIndex].AddPhoto(photo); }