public void MakeBmp(string path, int clickX, int clickY,
                            int widthOfResizedImage, int heightOfResizedImage, JpegRotationFinder shouldRotateImages)
        {
            Bmp.Dispose();
            Bmp = new Bitmap(MaxWidth, MaxHeight, PixelFormat.Format32bppPArgb);
            if (path == null || !FilenameUtils.LooksLikeImage(path) || !File.Exists(path))
            {
                return;
            }

            // we can disregard bitmapWillLockFile because we'll quickly dispose bitmapFull.
            using (Bitmap bitmapFull = ImageCache.GetBitmap(path, shouldRotateImages, out bool bitmapWillLockFile))
            {
                if (bitmapFull.Width == 1 || bitmapFull.Height == 1)
                {
                    return;
                }

                GetShiftAmount(bitmapFull, clickX, clickY,
                               widthOfResizedImage, heightOfResizedImage, out int shiftX, out int shiftY);

                // draw the entire image, but pushed off to the side
                using (Graphics g = Graphics.FromImage(Bmp))
                {
                    g.FillRectangle(Brushes.White, 0, 0, MaxWidth, MaxHeight);
                    g.DrawImageUnscaled(bitmapFull, -shiftX, -shiftY);
                }
            }
        }
Exemplo n.º 2
0
 static ModeBase GuessModeBasedOnFileExtensions(IEnumerable <string> paths)
 {
     if (!Configs.Current.GetBool(ConfigKey.EnablePersonalFeatures))
     {
         return(new ModeCategorizeAndRename());
     }
     else if (paths.Any(path => FilenameUtils.LooksLikeImage(path)))
     {
         return(new ModeCategorizeAndRename());
     }
     else if (paths.All(path =>
                        path.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) ||
                        path.EndsWith(".flac", StringComparison.OrdinalIgnoreCase)))
     {
         return(new ModeMarkWavQuality());
     }
     else
     {
         return(new ModeMarkMp3Quality());
     }
 }
Exemplo n.º 3
0
        public Bitmap GetResizedBitmap(string path, out int originalWidth, out int originalHeight)
        {
            if (!FilenameUtils.LooksLikeImage(path) || !File.Exists(path))
            {
                originalWidth  = 0;
                originalHeight = 0;
                return(new Bitmap(1, 1, PixelFormat.Format32bppPArgb));
            }

            Bitmap bitmapFull = GetBitmap(path, _shouldRotateThisImage, out bool bitmapWillLockFile);

            // resize and preserve ratio
            originalWidth  = bitmapFull.Width;
            originalHeight = bitmapFull.Height;
            if (bitmapFull.Width > MaxWidth || bitmapFull.Height > MaxHeight)
            {
                using (bitmapFull)
                {
                    var ratio = Math.Min((double)MaxWidth / bitmapFull.Width,
                                         (double)MaxHeight / bitmapFull.Height);

                    int newWidth  = (int)(bitmapFull.Width * ratio);
                    int newHeight = (int)(bitmapFull.Height * ratio);
                    return(ClassImageOps.ResizeImage(bitmapFull, newWidth, newHeight, this.ResizeToFit, path));
                }
            }
            else if (bitmapWillLockFile)
            {
                // make a copy of the bitmap, otherwise the file remains locked
                using (bitmapFull)
                {
                    return(new Bitmap(bitmapFull));
                }
            }
            else
            {
                return(bitmapFull);
            }
        }