private void SaveWeb(SaveWebFileSourceLocations fileSource, int rotate, Photo.EncoderStatusDelegate Status, Photo.MeaningfulActivityDelegate Active, bool updateStatus, bool allowEnlargedWeb) { int webMaxSide = 600; int thumbMaxSide = 180; System.Drawing.Image image = null; #region Get input image if (updateStatus) { Active(); Status(this.K + " Getting image..."); this.ProcessingProgress = 10; this.ProcessingLastChange = DateTime.Now; this.Update(); } if (fileSource == SaveWebFileSourceLocations.UploadTemporary) { image = System.Drawing.Image.FromStream(new MemoryStream(Storage.GetFromStore(Storage.Stores.Temporary, this.UploadTemporary, this.UploadTemporaryExtention))); } else { image = System.Drawing.Image.FromStream(new MemoryStream(Storage.GetFromStore(Storage.Stores.Master, this.Master, "jpg"))); } #endregion try { #region Convert any image with an indexed pixel format to JPG if (image.PixelFormat.Equals(PixelFormat.Format1bppIndexed) || image.PixelFormat.Equals(PixelFormat.Format4bppIndexed) || image.PixelFormat.Equals(PixelFormat.Format8bppIndexed) || image.PixelFormat.Equals(PixelFormat.Undefined) || image.PixelFormat.Equals(PixelFormat.DontCare) || image.PixelFormat.Equals(PixelFormat.Format16bppArgb1555) || image.PixelFormat.Equals(PixelFormat.Format16bppGrayScale)) { if (updateStatus) { Active(); Status(this.K + " Converting to indexed pixel format..."); this.ProcessingProgress = 11; this.ProcessingLastChange = DateTime.Now; this.Update(); } MemoryStream converterStream = new MemoryStream(); ImageCodecInfo jpgEncoder = ImageCodecInfo.GetImageEncoders()[1]; EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters(2); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); encoderParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24L); image.Save(converterStream, jpgEncoder, encoderParams); image.Dispose(); image = null; image = System.Drawing.Image.FromStream(converterStream); } #endregion #region Rotate image if (rotate > 0 && updateStatus) { Active(); Status(this.K + " Rotating..."); this.ProcessingProgress = 12; this.ProcessingLastChange = DateTime.Now; this.Update(); } if (rotate == 90) { image.RotateFlip(RotateFlipType.Rotate90FlipNone); } else if (rotate == 180) { image.RotateFlip(RotateFlipType.Rotate180FlipNone); } else if (rotate == 270) { image.RotateFlip(RotateFlipType.Rotate270FlipNone); } #endregion #region Save Master if (fileSource != SaveWebFileSourceLocations.Master) { if (updateStatus) { Active(); Status(this.K + " Saving master..."); this.ProcessingProgress = 20; this.ProcessingLastChange = DateTime.Now; this.Update(); } byte[] masterBytes = SaveJPGWithCompressionSetting(image, (long)85.0); Storage.AddToStore(masterBytes, Storage.Stores.Master, this.Master, "jpg", this, "Master"); this.MasterFileSize = masterBytes.Length; } #endregion #region Extract metadata if (fileSource == SaveWebFileSourceLocations.UploadTemporary) { try { if (updateStatus) { Active(); Status(this.K + " Extracting exif meta data..."); this.ProcessingProgress = 30; this.ProcessingLastChange = DateTime.Now; this.Update(); } Cambro.Misc.ExifMetadata MyExifMetadata = new Cambro.Misc.ExifMetadata(); Cambro.Misc.ExifMetadata.Metadata MyMetaData; MyMetaData = MyExifMetadata.GetExifMetadata(image); string date = MyMetaData.DatePictureTaken.DisplayValue; try { this.CameraModel = MyMetaData.CameraModel.DisplayValue.Truncate(100); } catch { } try { this.EquipmentMake = MyMetaData.EquipmentMake.DisplayValue.Truncate(100); } catch { } if (this.EquipmentMake.StartsWith("Sony Ericsson") && this.CameraModel.StartsWith("K800i")) this.IsSonyK800i = true; if (this.EquipmentMake.StartsWith("Sony Ericsson") && this.CameraModel.StartsWith("C902")) this.IsSonyC902 = true; int year = int.Parse(date.Substring(0, 4)); int month = int.Parse(date.Substring(5, 2)); int day = int.Parse(date.Substring(8, 2)); int hour = int.Parse(date.Substring(11, 2)); int min = int.Parse(date.Substring(14, 2)); int sec = int.Parse(date.Substring(17, 2)); DateTime newDateTime = new DateTime(year, month, day, hour, min, sec); DateTime parentDateTime = DateTime.Now; if (this.Event != null) { parentDateTime = this.Event.DateTime; TimeSpan difference = this.DateTime - newDateTime; if (Math.Abs(difference.TotalDays) < 10) { this.DateTime = newDateTime; } } else if (this.Article != null) { parentDateTime = this.Article.AddedDateTime; TimeSpan difference = this.DateTime - newDateTime; if (Math.Abs(difference.TotalDays) < 60) { this.DateTime = newDateTime; } } } catch { if (updateStatus) { Active(); Status(this.K + " Assigning default meta data..."); this.ProcessingProgress = 35; this.ProcessingLastChange = DateTime.Now; this.Update(); } if (this.Event != null) { this.DateTime = this.Event.DateTime; } else if (this.Article != null) { this.DateTime = this.Article.AddedDateTime; } else { this.DateTime = DateTime.Now; } } } #endregion #region Calculate the dimensions and landscape/portrait if (updateStatus) { Active(); Status(this.K + " Calculating sizes of new images..."); this.ProcessingProgress = 40; this.ProcessingLastChange = DateTime.Now; this.Update(); } this.OriginalHeight = image.Height; this.OriginalWidth = image.Width; this.IsLandscape = !(image.Height > image.Width); #endregion #region Save Web, Thumb and Icon #region Overlays... Overlays webOverlay = Overlays.DsiLogoBottomRight; if (this.IsSonyK800i) webOverlay = Overlays.DsiLogoBottomRightSonyBottomLeft; else if (this.IsSonyC902) webOverlay = Overlays.DsiLogoBottomRightSonyC902BottomLeft; this.Overlay = webOverlay; Overlays thumbOverlay = Overlays.None; Overlays iconOverlay = Overlays.None; if (this.MediaType.Equals(MediaTypes.Video)) { webOverlay = Overlays.PlayButtonLarge; thumbOverlay = Overlays.PlayButtonSmall; iconOverlay = Overlays.PlayButtonSmall; } #endregion #region Web if (updateStatus) { Active(); Status(this.K + " Creating web image..."); this.ProcessingProgress = 50; this.ProcessingLastChange = DateTime.Now; this.Update(); } OperationReturn web = Operation(image, OperationType.MaxSide, new OperationParams() { MaxSide = webMaxSide, Overlay = webOverlay, ReturnBytes = true, AllowMaxSideToEnlarge = allowEnlargedWeb }); this.WebWidth = web.ImageSize.Width; this.WebHeight = web.ImageSize.Height; Storage.AddToStore(web.Bytes, Storage.Stores.Pix, this.Web, "jpg", this, "Web"); #endregion #region Thumb if (updateStatus) { Active(); Status(this.K + " Creating thumb image..."); this.ProcessingProgress = 60; this.ProcessingLastChange = DateTime.Now; this.Update(); } OperationReturn thumb = Operation(image, OperationType.MaxSide, new OperationParams() { MaxSide = thumbMaxSide, Overlay = thumbOverlay, ReturnBytes = true, AllowMaxSideToEnlarge = true }); this.ThumbWidth = thumb.ImageSize.Width; this.ThumbHeight = thumb.ImageSize.Height; Storage.AddToStore(thumb.Bytes, Storage.Stores.Pix, this.Thumb, "jpg", this, "Thumb"); #endregion #region Icon if (updateStatus) { Active(); Status(this.K + " Creating icon image..."); this.ProcessingProgress = 70; this.ProcessingLastChange = DateTime.Now; this.Update(); } OperationReturn icon = Operation(image, OperationType.FixedSize, new OperationParams() { FixedSize = new Size(100, 100), Overlay = iconOverlay, ReturnBytes = true }); Storage.AddToStore(icon.Bytes, Storage.Stores.Pix, this.Icon, "jpg", this, "Icon"); #endregion #endregion #region Delete temporary upload file if (fileSource == SaveWebFileSourceLocations.UploadTemporary) { if (updateStatus) { Active(); Status(this.K + " Deleting temporary upload file..."); this.ProcessingProgress = 80; this.ProcessingLastChange = DateTime.Now; this.Update(); } //Delete will fail unless we dispose here as well as in the finally block!!! image.Dispose(); Storage.RemoveFromStore(Storage.Stores.Temporary, this.UploadTemporary, this.UploadTemporaryExtention); } #endregion } finally { if (image != null) image.Dispose(); } this.Update(); #region Done! if (updateStatus) { Active(); Status(this.K + " Done!"); this.ProcessingProgress = 100; this.ProcessingLastChange = DateTime.Now; this.Update(); } #endregion }
public void SaveWeb(SaveWebFileSourceLocations fileSource, int rotate, Photo.EncoderStatusDelegate Status, Photo.MeaningfulActivityDelegate Active) { SaveWeb(fileSource, rotate, Status, Active, Status != null, true); }
public void SaveWeb(SaveWebFileSourceLocations fileSource, int rotate, Photo.EncoderStatusDelegate Status, Photo.MeaningfulActivityDelegate Active, bool allowEnlargedWeb) { SaveWeb(fileSource, rotate, Status, Active, Status != null, allowEnlargedWeb); }
public void SaveWeb(SaveWebFileSourceLocations fileSource, int rotate) { SaveWeb(fileSource, rotate, null, null, false, true); }