public string Execute(FileItem item, string dest, ValuePairEnumerator configData) { var conf = new CropTransformViewModel(configData); using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(item.FileName))) { BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]); if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null) { var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties(); conf.Left = (int)(writeableBitmap.PixelWidth * prop.LiveviewSettings.HorizontalMin / 100); conf.Width = (int) (writeableBitmap.PixelWidth * (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin) / 100); conf.Top = (int)(writeableBitmap.Height * prop.LiveviewSettings.VerticalMin / 100); conf.Height = (int) (writeableBitmap.Height * (prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin) / 100); } BitmapLoader.Save2Jpg(writeableBitmap.Crop(conf.Left, conf.Top, conf.Width, conf.Height), dest); } return(dest); }
private void JpgButton_Click(object sender, RoutedEventArgs e) { try { var dialog = new SaveFileDialog { Filter = "Jpg files (*.jpg)|*.jpg|All files|*.*" }; if (dialog.ShowDialog() == true) { BitmapLoader.Save2Jpg( BitmapLoader.SaveImageSource(ItemsControl, (int)ItemsControl.Width, (int)ItemsControl.Height), dialog.FileName); } } catch (Exception exception) { this.ShowMessageAsync("Save error", exception.Message); Log.Error("Save error", exception); } }
public void CopyFile(string filename, string destFile) { using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(filename))) { BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); bmpDec.DownloadProgress += (o, args) => StaticHelper.Instance.LoadingProgress = args.Progress; double zw = (double)VideoType.Width / bmpDec.Frames[0].PixelWidth; double zh = (double)VideoType.Height / bmpDec.Frames[0].PixelHeight; double za = FillImage ? ((zw <= zh) ? zw : zh) : ((zw >= zh) ? zw : zh); WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(BitmapLoader.GetBitmapFrame(bmpDec.Frames[0], (int)(bmpDec.Frames[0].PixelWidth * za) / 2 * 2, (int)(bmpDec.Frames[0].PixelHeight * za) / 2 * 2, BitmapScalingMode.HighQuality)); BitmapLoader.Save2Jpg(writeableBitmap, destFile); } }
public string Execute(FileItem fileItem, string infile, string dest, ValuePairEnumerator configData) { var conf = new ResizeTransformViewModel(configData); bool deleteFile = false; var filename = infile; if (fileItem.IsRaw) { string s = Path.Combine(Path.GetDirectoryName(fileItem.FileName), Path.GetFileNameWithoutExtension(fileItem.FileName) + ".jpg"); if (File.Exists(s)) { filename = s; } else { string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe"); if (File.Exists(dcraw_exe)) { PhotoUtils.RunAndWait(dcraw_exe, string.Format(" -e {0}", fileItem.FileName)); string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName), Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg"); if (File.Exists(thumb)) { deleteFile = true; filename = thumb; } } } dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg"); } using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(filename))) { BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); WriteableBitmap writeableBitmap; if (conf.KeepAspect) { double dw = (double)conf.Width / bmpDec.Frames[0].PixelWidth; writeableBitmap = BitmapFactory.ConvertToPbgra32Format(BitmapLoader.GetBitmapFrame(bmpDec.Frames[0], (int)(bmpDec.Frames[0].PixelWidth * dw), (int)(bmpDec.Frames[0].PixelHeight * dw), BitmapScalingMode.Linear)); } else { writeableBitmap = BitmapFactory.ConvertToPbgra32Format(BitmapLoader.GetBitmapFrame(bmpDec.Frames[0], conf.Width, conf.Height, BitmapScalingMode.Linear)); } BitmapLoader.Save2Jpg(writeableBitmap, dest); // remove temporally file created by dcraw if (deleteFile) { File.Delete(filename); } } return(dest); }
public string ExecuteThread(FileItem item, string dest, ValuePairEnumerator configData) { var conf = new OverlayTransformViewModel(configData); using (var fileStream = new MemoryStream(File.ReadAllBytes(item.FileName))) { BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]); Grid grid = new Grid { Width = writeableBitmap.PixelWidth, Height = writeableBitmap.PixelHeight, ClipToBounds = true, SnapsToDevicePixels = true }; grid.UpdateLayout(); var size = new Size(writeableBitmap.PixelWidth, writeableBitmap.PixelWidth); grid.Measure(size); grid.Arrange(new Rect(size)); Image image = new Image { Width = writeableBitmap.PixelWidth, Height = writeableBitmap.PixelHeight }; image.BeginInit(); image.Source = writeableBitmap; image.EndInit(); image.Stretch = Stretch.Fill; grid.Children.Add(image); grid.UpdateLayout(); Regex regPattern = new Regex(@"\[(.*?)\]", RegexOptions.Singleline); MatchCollection matchX = regPattern.Matches(conf.Text); var text = matchX.Cast <Match>().Aggregate(conf.Text, (current1, match) => item.FileNameTemplates.Where(template => System.String.Compare(template.Name, match.Value, System.StringComparison.InvariantCultureIgnoreCase) == 0).Aggregate(current1, (current, template) => current.Replace(match.Value, template.Value))); TextBlock textBlock = new TextBlock { Text = text, Foreground = (SolidColorBrush) new BrushConverter().ConvertFromString(conf.FontColor), FontFamily = (FontFamily) new FontFamilyConverter().ConvertFromString(conf.Font), FontSize = conf.FontSize }; if (conf.A11) { textBlock.HorizontalAlignment = HorizontalAlignment.Left; textBlock.VerticalAlignment = VerticalAlignment.Top; } if (conf.A12) { textBlock.HorizontalAlignment = HorizontalAlignment.Center; textBlock.VerticalAlignment = VerticalAlignment.Top; } if (conf.A13) { textBlock.HorizontalAlignment = HorizontalAlignment.Right; textBlock.VerticalAlignment = VerticalAlignment.Top; } if (conf.A21) { textBlock.HorizontalAlignment = HorizontalAlignment.Left; textBlock.VerticalAlignment = VerticalAlignment.Center; } if (conf.A22) { textBlock.HorizontalAlignment = HorizontalAlignment.Center; textBlock.VerticalAlignment = VerticalAlignment.Center; } if (conf.A23) { textBlock.HorizontalAlignment = HorizontalAlignment.Right; textBlock.VerticalAlignment = VerticalAlignment.Center; } if (conf.A31) { textBlock.HorizontalAlignment = HorizontalAlignment.Left; textBlock.VerticalAlignment = VerticalAlignment.Bottom; } if (conf.A32) { textBlock.HorizontalAlignment = HorizontalAlignment.Center; textBlock.VerticalAlignment = VerticalAlignment.Bottom; } if (conf.A33) { textBlock.HorizontalAlignment = HorizontalAlignment.Right; textBlock.VerticalAlignment = VerticalAlignment.Bottom; } textBlock.Margin = new Thickness(conf.Margins); if (File.Exists(conf.OverlayFile)) { Image overlay = new Image(); overlay.Source = BitmapLoader.Instance.LoadImage(conf.OverlayFile, 0, 0); if (!conf.StrechOverlay) { overlay.HorizontalAlignment = textBlock.HorizontalAlignment; overlay.VerticalAlignment = textBlock.VerticalAlignment; overlay.Stretch = Stretch.None; } else { overlay.HorizontalAlignment = HorizontalAlignment.Stretch; overlay.VerticalAlignment = VerticalAlignment.Stretch; overlay.Stretch = Stretch.UniformToFill; } grid.Children.Add(overlay); grid.UpdateLayout(); } grid.Children.Add(textBlock); grid.UpdateLayout(); BitmapLoader.Save2Jpg( BitmapLoader.SaveImageSource(grid, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight), dest); } return(dest); }