예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }