Esempio n. 1
0
        public void SetData(BitmapFile file, FileItem fileItem)
        {
            if (fileItem == null || fileItem.FileInfo == null)
            {
                return;
            }
            fileItem.LoadInfo();
            file.FileName = Path.GetFileNameWithoutExtension(fileItem.FileName);
            file.Comment  = "";
            if (fileItem.FileInfo.ExifTags.ContainName("Iptc.Application2.Caption"))
            {
                file.Comment = fileItem.FileInfo.ExifTags["Iptc.Application2.Caption"];
            }

            file.Metadata.Clear();
            foreach (ValuePair item in fileItem.FileInfo.ExifTags.Items)
            {
                file.Metadata.Add(new DictionaryItem()
                {
                    Name = item.Name, Value = item.Value
                });
            }
            file.BlueColorHistogramPoints  = ConvertToPointCollection(fileItem.FileInfo.HistogramBlue);
            file.RedColorHistogramPoints   = ConvertToPointCollection(fileItem.FileInfo.HistogramRed);
            file.GreenColorHistogramPoints = ConvertToPointCollection(fileItem.FileInfo.HistogramGreen);
            file.LuminanceHistogramPoints  = ConvertToPointCollection(fileItem.FileInfo.HistogramLuminance);

            file.InfoLabel  = Path.GetFileName(file.FileItem.FileName);
            file.InfoLabel += String.Format(" | {0}x{1}", fileItem.FileInfo.Width, fileItem.FileInfo.Height);
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.ExposureTime"))
            {
                file.InfoLabel += " | E " + fileItem.FileInfo.ExifTags["Exif.Photo.ExposureTime"];
            }
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.FNumber"))
            {
                file.InfoLabel += " | " + fileItem.FileInfo.ExifTags["Exif.Photo.FNumber"];
            }
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.ISOSpeedRatings"))
            {
                file.InfoLabel += " | ISO " + fileItem.FileInfo.ExifTags["Exif.Photo.ISOSpeedRatings"];
            }
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.ExposureBiasValue"))
            {
                file.InfoLabel += " | " + fileItem.FileInfo.ExifTags["Exif.Photo.ExposureBiasValue"];
            }
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.FocalLength"))
            {
                file.InfoLabel += " | " + fileItem.FileInfo.ExifTags["Exif.Photo.FocalLength"];
            }
        }
Esempio n. 2
0
        public void SetData(BitmapFile file, FileItem fileItem)
        {
            if (fileItem == null || fileItem.FileInfo == null)
                return;
            fileItem.LoadInfo();
            file.FileName = Path.GetFileNameWithoutExtension(fileItem.FileName);
            file.Comment = "";
            if (fileItem.FileInfo.ExifTags.ContainName("Iptc.Application2.Caption"))
                file.Comment = fileItem.FileInfo.ExifTags["Iptc.Application2.Caption"];

            file.Metadata.Clear();
            foreach (ValuePair item in fileItem.FileInfo.ExifTags.Items)
            {
                file.Metadata.Add(new DictionaryItem() { Name = item.Name, Value = item.Value });
            }
            file.BlueColorHistogramPoints = ConvertToPointCollection(fileItem.FileInfo.HistogramBlue);
            file.RedColorHistogramPoints = ConvertToPointCollection(fileItem.FileInfo.HistogramRed);
            file.GreenColorHistogramPoints = ConvertToPointCollection(fileItem.FileInfo.HistogramGreen);
            file.LuminanceHistogramPoints = ConvertToPointCollection(fileItem.FileInfo.HistogramLuminance);

            // file.InfoLabel = Path.GetFileName(file.FileItem.FileName);
            file.InfoLabel = "";
            //file.InfoLabel += String.Format(" | {0}x{1}", fileItem.FileInfo.Width, fileItem.FileInfo.Height);
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.ExposureTime"))
            {
                file.InfoLabel += "E " + fileItem.FileInfo.ExifTags["Exif.Photo.ExposureTime"];
            }
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.FNumber"))
            {
                file.InfoLabel += " | " + fileItem.FileInfo.ExifTags["Exif.Photo.FNumber"];
            }
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.ISOSpeedRatings"))
            {
                file.InfoLabel += " | ISO " + fileItem.FileInfo.ExifTags["Exif.Photo.ISOSpeedRatings"];
            }
            if (fileItem.FileInfo.ExifTags.ContainName("Exif.Photo.FocalLength"))
            {
                file.InfoLabel += " | " + fileItem.FileInfo.ExifTags["Exif.Photo.FocalLength"];
            }
            SetImageInfo(fileItem);
        }
Esempio n. 3
0
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres, bool showfocuspoints)
        {
            if (fileItem == null)
                return null;
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
                return null;
            if (File.Exists(fileItem.InfoFile))
                fileItem.LoadInfo();
            if (fileItem.FileInfo == null)
                fileItem.FileInfo = new FileInfo();

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && fileItem.IsRaw)
                {
                    try
                    {
                        string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                        if (File.Exists(dcraw_exe))
                        {
                            string thumb = Path.Combine(Path.GetTempPath(),
                                Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                            PhotoUtils.RunAndWait(dcraw_exe,
                                string.Format(" -e -O \"{0}\" \"{1}\"", thumb, fileItem.FileName));
                            if (File.Exists(thumb))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                PhotoUtils.WaitForFile(fullres ? fileItem.FileName : fileItem.LargeThumb);
                if (bmpDec == null)
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                        BitmapCreateOptions.None,
                        BitmapCacheOption.OnLoad);
                // if no future processing required
                if (!showfocuspoints && ServiceProvider.Settings.RotateIndex == 0 && !ServiceProvider.Settings.FlipPreview)
                {
                    fileItem.Loading = false;
                    var b = new WriteableBitmap(bmpDec.Frames[0]);
                    b.Freeze();
                    return b;
                }

                var bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);

                if (showfocuspoints && !fileItem.Transformed)
                    DrawFocusPoints(fileItem, bitmap);

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                        case 1:
                            bitmap = bitmap.Rotate(90);
                            break;
                        case 2:
                            bitmap = bitmap.Rotate(180);
                            break;
                        case 3:
                            bitmap = bitmap.Rotate(270);
                            break;
                    }
                }

                if (ServiceProvider.Settings.FlipPreview)
                {
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }

                bitmap.Freeze();
                return bitmap;
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
                if (exception.GetType() == typeof(OutOfMemoryException) && fullres)
                {
                    return LoadImage(fileItem, false);
                }
            }
            return null;
        }
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres, bool showfocuspoints)
        {
            if (fileItem == null)
            {
                return(null);
            }
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
            {
                return(null);
            }
            if (File.Exists(fileItem.InfoFile))
            {
                fileItem.LoadInfo();
            }
            if (fileItem.FileInfo == null)
            {
                fileItem.FileInfo = new FileInfo();
            }

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && fileItem.IsRaw)
                {
                    try
                    {
                        string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                        if (File.Exists(dcraw_exe))
                        {
                            string thumb = Path.Combine(Path.GetTempPath(),
                                                        Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                            PhotoUtils.RunAndWait(dcraw_exe,
                                                  string.Format(" -e -O \"{0}\" \"{1}\"", thumb, fileItem.FileName));
                            if (File.Exists(thumb))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                PhotoUtils.WaitForFile(fullres ? fileItem.FileName : fileItem.LargeThumb);
                if (bmpDec == null)
                {
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                                                  BitmapCreateOptions.None,
                                                  BitmapCacheOption.OnLoad);
                }
                // if no future processing required
                if (!showfocuspoints && ServiceProvider.Settings.RotateIndex == 0 && !ServiceProvider.Settings.FlipPreview)
                {
                    fileItem.Loading = false;
                    var b = new WriteableBitmap(bmpDec.Frames[0]);
                    b.Freeze();
                    return(b);
                }

                var bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);

                if (showfocuspoints && !fileItem.Transformed)
                {
                    DrawFocusPoints(fileItem, bitmap);
                }


                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                    case 1:
                        bitmap = bitmap.Rotate(90);
                        break;

                    case 2:
                        bitmap = bitmap.Rotate(180);
                        break;

                    case 3:
                        bitmap = bitmap.Rotate(270);
                        break;
                    }
                }

                if (ServiceProvider.Settings.FlipPreview)
                {
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }

                bitmap.Freeze();
                return(bitmap);
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
                if (exception.GetType() == typeof(OutOfMemoryException) && fullres)
                {
                    return(LoadImage(fileItem, false));
                }
            }
            return(null);
        }
Esempio n. 5
0
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres, bool showfocuspoints)
        {
            int rotation = 0;

            if (fileItem == null)
            {
                return(null);
            }
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
            {
                return(null);
            }

            if (File.Exists(fileItem.InfoFile))
            {
                fileItem.LoadInfo();
            }
            else
            {
                fileItem.FileInfo = new FileInfo();
            }

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && fileItem.IsRaw)
                {
                    try
                    {
                        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))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                if (ServiceProvider.Settings.Autorotate && fileItem.FileInfo != null && fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation"))
                {
                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                    {
                        rotation = 180;
                    }

                    //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                    //    bitmap = bitmap.Rotate(180);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                    {
                        rotation = 90;
                    }

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                    {
                        rotation = 270;
                    }
                }

                if (bmpDec == null)
                {
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                                                  BitmapCreateOptions.None,
                                                  BitmapCacheOption.OnLoad);
                }
                // if no future processing required
                if (rotation == 0 && !showfocuspoints && ServiceProvider.Settings.RotateIndex == 0 && ServiceProvider.Settings.FlipPreview)
                {
                    return(new WriteableBitmap(bmpDec.Frames[0]));
                }


                var bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);


                if (showfocuspoints)
                {
                    DrawFocusPoints(fileItem, bitmap);
                }

                if (rotation != 0)
                {
                    bitmap = bitmap.Rotate(rotation);
                }

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                    case 1:
                        bitmap = bitmap.Rotate(90);
                        break;

                    case 2:
                        bitmap = bitmap.Rotate(180);
                        break;

                    case 3:
                        bitmap = bitmap.Rotate(270);
                        break;
                    }
                }

                if (ServiceProvider.Settings.FlipPreview)
                {
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }

                bitmap.Freeze();
                return(bitmap);
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
            }
            return(null);
        }
Esempio n. 6
0
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres, bool showfocuspoints)
        {
            int rotation = 0;
            if (fileItem == null)
                return null;
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
                return null;

            if (File.Exists(fileItem.InfoFile))
                fileItem.LoadInfo();
            else
                fileItem.FileInfo = new FileInfo();

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && fileItem.IsRaw)
                {
                    try
                    {
                        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))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb),BitmapCreateOptions.None,BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                if (ServiceProvider.Settings.Autorotate && fileItem.FileInfo != null && fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation"))
                {
                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                        rotation = 180;

                    //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                    //    bitmap = bitmap.Rotate(180);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                        rotation = 90;

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                        rotation = 270;

                }

                if (bmpDec == null)
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                        BitmapCreateOptions.None,
                        BitmapCacheOption.OnLoad);
                // if no future processing required
                if (rotation == 0 && !showfocuspoints && ServiceProvider.Settings.RotateIndex == 0 && ServiceProvider.Settings.FlipPreview)
                {
                    return new WriteableBitmap(bmpDec.Frames[0]);
                }

                var bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);

                if (showfocuspoints)
                    DrawFocusPoints(fileItem, bitmap);

                if (rotation != 0)
                    bitmap = bitmap.Rotate(rotation);

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                        case 1:
                            bitmap = bitmap.Rotate(90);
                            break;
                        case 2:
                            bitmap = bitmap.Rotate(180);
                            break;
                        case 3:
                            bitmap = bitmap.Rotate(270);
                            break;
                    }
                }

                if (ServiceProvider.Settings.FlipPreview)
                {
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }

                bitmap.Freeze();
                return bitmap;
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
            }
            return null;
        }
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres)
        {
            if (ServiceProvider.Settings.LowMemoryUsage)
                fullres = false;

            if (fileItem == null)
                return null;
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
                return null;

            if (File.Exists(fileItem.InfoFile))
                fileItem.LoadInfo();
            else
                fileItem.FileInfo = new FileInfo();

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && fileItem.IsRaw)
                {
                    try
                    {
                        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))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb),BitmapCreateOptions.None,BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                if (bmpDec == null)
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                        BitmapCreateOptions.None,
                        BitmapCacheOption.OnLoad);

                double dw = (double) MaxThumbSize/bmpDec.Frames[0].PixelWidth;
                WriteableBitmap bitmap;
                if (fullres)
                    bitmap =
                        BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                                                                            (int) (bmpDec.Frames[0].PixelWidth*dw),
                                                                            (int) (bmpDec.Frames[0].PixelHeight*dw),
                                                                            BitmapScalingMode.NearestNeighbor));
                else
                    bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);

                if (ServiceProvider.Settings.ShowFocusPoints)
                    DrawFocusPoints(fileItem, bitmap);

                if (fileItem.FileInfo !=null && fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation") )
                {
                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                        bitmap = bitmap.Rotate(180);

                    //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                    //    bitmap = bitmap.Rotate(180);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                        bitmap = bitmap.Rotate(90);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                        bitmap = bitmap.Rotate(270);
                }

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                        case 1:
                            bitmap = bitmap.Rotate(90);
                            break;
                        case 2:
                            bitmap = bitmap.Rotate(180);
                            break;
                        case 3:
                            bitmap = bitmap.Rotate(270);
                            break;
                    }
                }

                bitmap.Freeze();
                return bitmap;
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
            }
            return null;
        }
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres)
        {
            if (ServiceProvider.Settings.LowMemoryUsage)
                fullres = false;

            if (fileItem == null)
                return null;
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
                return null;

            if (File.Exists(fileItem.InfoFile))
                fileItem.LoadInfo();
            else
                fileItem.FileInfo = new FileInfo();

            try
            {
                BitmapDecoder bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                                                            BitmapCreateOptions.None,
                                                            BitmapCacheOption.OnLoad);

                double dw = (double)MaxThumbSize / bmpDec.Frames[0].PixelWidth;
                WriteableBitmap bitmap;
                if(fullres)
                bitmap =
                    BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                                                                        (int)(bmpDec.Frames[0].PixelWidth * dw),
                                                                        (int)(bmpDec.Frames[0].PixelHeight * dw),
                                                                        BitmapScalingMode.NearestNeighbor));
                else
                    bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);

                if (ServiceProvider.Settings.ShowFocusPoints)
                    DrawFocusPoints(fileItem, bitmap);

                if (fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation") && !fileItem.IsRaw)
                {
                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                        bitmap =  bitmap.Rotate(180);

                    //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                    //    bitmap = bitmap.Rotate(180);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                        bitmap = bitmap.Rotate(90);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                        bitmap = bitmap.Rotate(270);
                }

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                        case 1:
                            bitmap = bitmap.Rotate(90);
                            break;
                        case 2:
                            bitmap = bitmap.Rotate(180);
                            break;
                        case 3:
                            bitmap = bitmap.Rotate(270);
                            break;
                    }
                }

                bitmap.Freeze();
                return bitmap;
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
            }
            return null;
        }
Esempio n. 9
0
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres)
        {
            if (ServiceProvider.Settings.LowMemoryUsage)
            {
                fullres = false;
            }

            if (fileItem == null)
            {
                return(null);
            }
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
            {
                return(null);
            }

            if (File.Exists(fileItem.InfoFile))
            {
                fileItem.LoadInfo();
            }
            else
            {
                fileItem.FileInfo = new FileInfo();
            }

            try
            {
                BitmapDecoder bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                                                            BitmapCreateOptions.None,
                                                            BitmapCacheOption.OnLoad);

                double          dw = (double)MaxThumbSize / bmpDec.Frames[0].PixelWidth;
                WriteableBitmap bitmap;
                if (fullres)
                {
                    bitmap =
                        BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                                                                            (int)(bmpDec.Frames[0].PixelWidth * dw),
                                                                            (int)(bmpDec.Frames[0].PixelHeight * dw),
                                                                            BitmapScalingMode.NearestNeighbor));
                }
                else
                {
                    bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
                }

                if (ServiceProvider.Settings.ShowFocusPoints)
                {
                    DrawFocusPoints(fileItem, bitmap);
                }

                if (fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation") && !fileItem.IsRaw)
                {
                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                    {
                        bitmap = bitmap.Rotate(180);
                    }

                    //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                    //    bitmap = bitmap.Rotate(180);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                    {
                        bitmap = bitmap.Rotate(90);
                    }

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                    {
                        bitmap = bitmap.Rotate(270);
                    }
                }

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                    case 1:
                        bitmap = bitmap.Rotate(90);
                        break;

                    case 2:
                        bitmap = bitmap.Rotate(180);
                        break;

                    case 3:
                        bitmap = bitmap.Rotate(270);
                        break;
                    }
                }

                bitmap.Freeze();
                return(bitmap);
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
            }
            return(null);
        }
Esempio n. 10
0
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres, bool showfocuspoints)
        {
            if (ServiceProvider.Settings.LowMemoryUsage)
            {
                fullres = false;
            }

            if (fileItem == null)
            {
                return(null);
            }
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
            {
                return(null);
            }

            if (File.Exists(fileItem.InfoFile))
            {
                fileItem.LoadInfo();
            }
            else
            {
                fileItem.FileInfo = new FileInfo();
            }

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && fileItem.IsRaw)
                {
                    try
                    {
                        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))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                if (bmpDec == null)
                {
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                                                  BitmapCreateOptions.None,
                                                  BitmapCacheOption.OnLoad);
                }

                double          dw = (double)MaxThumbSize / bmpDec.Frames[0].PixelWidth;
                WriteableBitmap bitmap;

                /*
                 * if (fullres)
                 *  bitmap =
                 *      BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                 *                                                          (int) (bmpDec.Frames[0].PixelWidth*dw),
                 *                                                          (int) (bmpDec.Frames[0].PixelHeight*dw),
                 *                                                          BitmapScalingMode.NearestNeighbor));
                 * else
                 *  bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
                 */
                bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);

                if (showfocuspoints)
                {
                    DrawFocusPoints(fileItem, bitmap);
                }

                if (fileItem.FileInfo != null && fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation"))
                {
                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                    {
                        bitmap = bitmap.Rotate(180);
                    }

                    //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                    //    bitmap = bitmap.Rotate(180);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                    {
                        bitmap = bitmap.Rotate(90);
                    }

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                    {
                        bitmap = bitmap.Rotate(270);
                    }
                }

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                    case 1:
                        bitmap = bitmap.Rotate(90);
                        break;

                    case 2:
                        bitmap = bitmap.Rotate(180);
                        break;

                    case 3:
                        bitmap = bitmap.Rotate(270);
                        break;
                    }
                }

                if (ServiceProvider.Settings.FlipPreview)
                {
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }

                bitmap.Freeze();
                return(bitmap);
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
            }
            return(null);
        }