Exemple #1
0
 public static Bitmap resize(this Bitmap bitmap, int width, int height)
 {
     // create filter
     AForge.Imaging.Filters.ResizeBicubic filter = new AForge.Imaging.Filters.ResizeBicubic(width, height);
     // apply the filter
     return(filter.Apply(bitmap));
 }
Exemple #2
0
        /// <summary>
        /// Adds the photo.
        /// </summary>
        public static void AddPhoto()
        {
            string thumbnailPath    = ConfigurationManager.AppSettings["thumbnailDirectory"].ToString();
            string connectionString = ConnectionStringHelper.GetActualConnectionString();

            OpenFileDialog openImage = new OpenFileDialog();

            openImage.Filter = "Pliki obrazów (*.jpg, *.png, *.crt, *.tiff)|*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG;*.crt;*.CRT;*.tiff;*.TIFF|Wszystkie pliki (*.*)|*.*";
            openImage.ShowDialog();

            if (openImage.CheckFileExists && !string.IsNullOrWhiteSpace(openImage.FileName))
            {
                string openedImageName = openImage.FileName;
                string fileName        = Path.GetFileName(openedImageName);
                string filePath        = openedImageName.Substring(0, openedImageName.Length - fileName.Length);
                string newFilePath     = ChangePath(filePath);

                Bitmap image = AForge.Imaging.Image.FromFile(openedImageName);

                int[] thumbnailSizes = GetThumbnailSize(image.Width, image.Height);

                int thumbnailWidth  = thumbnailSizes[0];
                int thumbnailHeight = thumbnailSizes[1];

                AForge.Imaging.Filters.ResizeBicubic filter = new AForge.Imaging.Filters.ResizeBicubic(thumbnailWidth, thumbnailHeight);
                Bitmap thumbnail = filter.Apply(image);

                string thumbnailFileName  = LookForFreeFilename(thumbnailPath, fileName);
                string thumbnailSavedPath = Path.Combine(thumbnailPath, thumbnailFileName);

                thumbnail.Save(thumbnailSavedPath);
                newFilePath = newFilePath + fileName;

                PhotosDataSource db          = new PhotosDataSource(connectionString);
                Photo            photoObject = new Photo();

                photoObject.FilePath      = newFilePath;
                photoObject.ThumbnailPath = thumbnailSavedPath;

                photoObject.Title       = fileName;
                photoObject.Description = string.Empty;

                photoObject.Archive   = null;
                photoObject.Attribute = null;

                db.AddPhoto(photoObject);
            }
        }
        /// <summary>
        /// Adds the photo.
        /// </summary>
        public static void AddPhoto()
        {
            string thumbnailPath = ConfigurationManager.AppSettings["thumbnailDirectory"].ToString();
            string connectionString = ConnectionStringHelper.GetActualConnectionString();

            OpenFileDialog openImage = new OpenFileDialog();
            openImage.Filter = "Pliki obrazów (*.jpg, *.png, *.crt, *.tiff)|*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG;*.crt;*.CRT;*.tiff;*.TIFF|Wszystkie pliki (*.*)|*.*";
            openImage.ShowDialog();

            if (openImage.CheckFileExists && !string.IsNullOrWhiteSpace(openImage.FileName))
            {
                string openedImageName = openImage.FileName;
                string fileName = Path.GetFileName(openedImageName);
                string filePath = openedImageName.Substring(0, openedImageName.Length - fileName.Length);
                string newFilePath = ChangePath(filePath);

                Bitmap image = AForge.Imaging.Image.FromFile(openedImageName);

                int[] thumbnailSizes = GetThumbnailSize(image.Width, image.Height);

                int thumbnailWidth = thumbnailSizes[0];
                int thumbnailHeight = thumbnailSizes[1];

                AForge.Imaging.Filters.ResizeBicubic filter = new AForge.Imaging.Filters.ResizeBicubic(thumbnailWidth, thumbnailHeight);
                Bitmap thumbnail = filter.Apply(image);

                string thumbnailFileName = LookForFreeFilename(thumbnailPath, fileName);
                string thumbnailSavedPath = Path.Combine(thumbnailPath, thumbnailFileName);

                thumbnail.Save(thumbnailSavedPath);
                newFilePath = newFilePath + fileName;

                PhotosDataSource db = new PhotosDataSource(connectionString);
                Photo photoObject = new Photo();

                photoObject.FilePath = newFilePath;
                photoObject.ThumbnailPath = thumbnailSavedPath;

                photoObject.Title = fileName;
                photoObject.Description = string.Empty;

                photoObject.Archive = null;
                photoObject.Attribute = null;

                db.AddPhoto(photoObject);
            }
        }
Exemple #4
0
 public static Bitmap resize(this Bitmap bitmap, int width, int height)
 {
     AForge.Imaging.Filters.ResizeBicubic filter = new AForge.Imaging.Filters.ResizeBicubic(width, height);
     return filter.Apply(bitmap);
 }
Exemple #5
0
        private void btnNormalize_Click(object sender, EventArgs e)
        {
            DirectoryInfo root = new DirectoryInfo(txtPath.Text);
            DirectoryInfo[] catagories = root.GetDirectories();
            foreach (DirectoryInfo catagory in catagories)
            {
                FileInfo[] files = catagory.GetFiles("*.jpg");
                foreach (FileInfo file in files)
                {
                    Image image = Image.FromFile(file.FullName);
                    float ratio = 384.0f / ((float)image.Height);
                    int width = (int)(ratio * image.Width);

                    Bitmap b = AForge.Imaging.Image.Clone((Bitmap)image, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                    AForge.Imaging.Filters.ResizeBicubic bc = new AForge.Imaging.Filters.ResizeBicubic(10, 15);

                    //AForge.Imaging.Filters.Crop cp = new AForge.Imaging.Filters.Crop(new Rectangle((image.Width - 256)/2, 0, 256, 384));
                    b =bc.Apply(b);
                    //b = cp.Apply(b);
                    b.Save(file.FullName+".new.jpg");
                    image.Dispose();
                    file.Delete();
                    new FileInfo(file.FullName + ".new.jpg").MoveTo(file.FullName);

                }

            }
        }
Exemple #6
0
        private Bitmap resize(Bitmap image, int newWidth, int newHeight)
        {
            if (keepAspectRatio)
            {

                double ratio = (double)newHeight / (double)image.Height;
                newWidth = (int)((double)image.Width * ratio);

            }

            AForge.Imaging.Filters.Crop cropper = new AForge.Imaging.Filters.Crop(new Rectangle(0, 0, newWidth, newHeight));

            if (cmbScalingMethod.SelectedIndex == 0)
            {
                AForge.Imaging.Filters.ResizeNearestNeighbor resizer = new AForge.Imaging.Filters.ResizeNearestNeighbor(newWidth, newHeight);
                image = cropper.Apply(resizer.Apply((Bitmap)image));
            }
            if (cmbScalingMethod.SelectedIndex == 1)
            {
                AForge.Imaging.Filters.ResizeBicubic resizer = new AForge.Imaging.Filters.ResizeBicubic(newWidth, newHeight);
                image = cropper.Apply(resizer.Apply((Bitmap)image));
            }
            if (cmbScalingMethod.SelectedIndex == 2)
            {
                AForge.Imaging.Filters.ResizeBilinear resizer = new AForge.Imaging.Filters.ResizeBilinear(newWidth, newHeight);
                image = cropper.Apply(resizer.Apply((Bitmap)image));
            }

            return image;
        }