/// <summary> /// Creates an embedded shadow copy of a source image file. /// </summary> /// <param name="sourceFile"></param> /// <param name="fileService"></param> private void CreateShadowFile(ImageFileData sourceFile, ISupportingFileService fileService) { Size shadowSize = new Size(1280, 960); using (MemoryStream shadowStream = new MemoryStream()) { ImageFormat format; string fileExt; ImageHelper2.GetImageFormat(sourceFile.SupportingFile.FileName, out fileExt, out format); using (Bitmap sourceImage = new Bitmap(sourceFile.Uri.LocalPath)) { if (sourceImage.Width > shadowSize.Width || sourceImage.Height > shadowSize.Height) { shadowSize = ImageHelper2.SaveScaledThumbnailImage(Math.Min(shadowSize.Width, sourceImage.Width), Math.Min(shadowSize.Height, sourceImage.Height), sourceImage, format, shadowStream); } else { shadowSize = sourceImage.Size; using (FileStream fs = File.OpenRead(sourceFile.Uri.LocalPath)) { StreamHelper.Transfer(fs, shadowStream); } } } shadowStream.Seek(0, SeekOrigin.Begin); ISupportingFile supportingFile = fileService.CreateSupportingFile(sourceFile.SupportingFile.FileName, shadowStream); _imageSourceShadowFile = new ImageFileData(supportingFile, shadowSize.Width, shadowSize.Height, ImageFileRelationship.SourceShadow); } }
public static Size WriteImageToFile(string sourceFile, int width, int height, string outputFile, bool preserveConstraints) { using (Bitmap sourceImage = new Bitmap(sourceFile)) { FixImageOrientation(sourceImage); using (Stream imageOut = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { ImageFormat format; string fileExt; ImageHelper2.GetImageFormat(sourceFile, out fileExt, out format); if (preserveConstraints) { ImageHelper2.SaveScaledThumbnailImage(width, height, sourceImage, format, imageOut); } else { ImageHelper2.SaveThumbnailImage(width, height, sourceImage, format, imageOut); } } } if (preserveConstraints) { using (Bitmap img = new Bitmap(outputFile)) return(img.Size); } else { return(new Size(width, height)); } }