Exemplo n.º 1
0
        private void okButton_Click(object sender, EventArgs e)
        {
            try
            {
                // get new image size
                int width  = Math.Max(1, Math.Min(5000, int.Parse(widthBox.Text)));
                int height = Math.Max(1, Math.Min(5000, int.Parse(heightBox.Text)));

                // create appropriate filter
                switch (methodCombo.SelectedIndex)
                {
                case 0:
                    filter = new ResizeNearestNeighbor(width, height);
                    break;

                case 1:
                    filter = new ResizeBilinear(width, height);
                    break;

                case 2:
                    filter = new ResizeBicubic(width, height);
                    break;
                }

                // close the dialog
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show(this, "Incorrect values are entered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes specified filter on an image. As destination image size may be different from source; in-place filtering is not allowed.
        /// </summary>
        /// <param name="img">Image.</param>
        /// <param name="filter">AForge <see cref="BaseTransformationFilter"/>.</param>
        public static TColor[,] ApplyBaseResizeFilter <TColor>(this TColor[,] img, BaseResizeFilter filter)
        where TColor : struct, IColor
        {
            TColor[,] dest = new TColor[filter.NewHeight, filter.NewWidth];

            using (var uImg = img.Lock())
                using (var uDest = dest.Lock())
                {
                    filter.Apply(uImg.AsAForgeImage(), uDest.AsAForgeImage());
                }

            return(dest);
        }