Ejemplo n.º 1
0
        /* 利用双线性插值把图片缩放为2的幂次方
         * 寻找最近的值来进行缩放,表已经在初始化时计算好了
         */
        static public Bitmap scale2SquareSize(Bitmap bit)
        {
            // 找出长宽的大值,用于缩放
            int tempM = 0;
            // 存放目标分辨率大小
            int size   = 0;
            int width  = bit.Width;
            int height = bit.Height;

            if (width <= height)
            {
                tempM = height;
            }
            else
            {
                tempM = width;
            }

            for (int i = 0; i < 16; i++)
            {
                if (tempM == array4two[i])
                {
                    size = array4two[i];
                    break;
                }
                if (tempM > array4two[i])
                {
                    continue;
                }

                if (tempM - array4two[i - 1] > array4two[i] - tempM)
                {
                    size = array4two[i];
                    break;
                }
                else
                {
                    size = array4two[i - 1];
                    break;
                }
            }
            return(GraphicClass.bilinearInterpolation(bit, size, size));
        }
Ejemplo n.º 2
0
        private void bilinerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            checkPictureBox1();
            if (!valid)
            {
                return;
            }

            Bitmap bit = new Bitmap(pictureBox1.Image);

            PassValueForm form = new PassValueForm();

            form.Owner       = this;
            form.Description = "输入要变化成的分辨率, 上面为宽,下面为长";
            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                pictureBox2.Refresh();
                int width  = Convert.ToInt32(form.Value);
                int height = Convert.ToInt32(form.Value1);
                pictureBox2.Image = GraphicClass.bilinearInterpolation(bit, width, height);
            }
        }