Ejemplo n.º 1
0
        public static bool RotateByPoints(Image img, ref Bitmap bm, Point p1, Point p2)
        {
            if ((p1.X == p2.X))                     // no need to rotate
            {
                return(true);
            }
            Point midPt = new Point();

            midPt.X = (int)((p1.X + p2.X) / 2.0);
            midPt.Y = (int)((p1.Y + p2.Y) / 2.0);
            double RotRadians = Math.Atan2(-(p2.Y - p1.Y), (p2.X - p1.X));
            Point  newmidPt   = new Point();

            newmidPt.X = (int)(midPt.X * Math.Cos(RotRadians) -
                               midPt.Y * Math.Sin(RotRadians));
            newmidPt.Y = (int)(midPt.Y * Math.Cos(RotRadians) +
                               midPt.X * Math.Sin(RotRadians));
            //MessageBox.Show(newmidPt.ToString());


            double Rot = RotRadians * 180 / 3.141516;

            return(MyImageProc.RotateFill2(img, ref bm, Rot, midPt, newmidPt));
        }
Ejemplo n.º 2
0
        private void convolveKernel_Click(object sender, EventArgs e)
        {
            try
            {
                double[][] kernel = new double[3][];
                for (int i = 0; i < 3; i++)
                {
                    kernel[i] = new double[3];
                }

                /*kernel[0][0] = 1 / 9.0;
                *  kernel[0][1] = 1 / 9.0;
                *  kernel[0][2] = 1 / 9.0;
                *  kernel[1][0] = 1 / 9.0;
                *  kernel[1][1] = 1 / 9.0;
                *  kernel[1][2] = 1 / 9.0;
                *  kernel[2][0] = 1 / 9.0;
                *  kernel[2][1] = 1 / 9.0;
                *  kernel[2][2] = 1 / 9.0;*/

                //kernel[0][0] = 0;
                //kernel[0][1] = -1;
                //kernel[0][2] = 0;
                //kernel[1][0] = -1;
                //kernel[1][1] = 5;
                //kernel[1][2] = -1;
                //kernel[2][0] = 0;
                //kernel[2][1] = -1;
                //kernel[2][2] = 0;

                kernel[0][0] = float.Parse(r1col1.Text);
                kernel[0][1] = float.Parse(r1col2.Text);
                kernel[0][2] = float.Parse(r1col3.Text);
                kernel[1][0] = float.Parse(r2col1.Text);
                kernel[1][1] = float.Parse(r2col2.Text);
                kernel[1][2] = float.Parse(r2col3.Text);
                kernel[2][0] = float.Parse(r3col1.Text);
                kernel[2][1] = float.Parse(r3col2.Text);
                kernel[2][2] = float.Parse(r3col3.Text);



                //kernel[0][0] = -1;
                //kernel[0][1] = -1;
                //kernel[0][2] = -1;
                //kernel[1][0] = 0;
                //kernel[1][1] = 0;
                //kernel[1][2] = 0;
                //kernel[2][0] = 1;
                //kernel[2][1] = 1;
                //kernel[2][2] = 1;
                Bitmap bmpNew = (Bitmap)bmpOrig.Clone();
                MyImageProc.Convolve(bmpOrig, kernel);
                orgPicture.Image = bmpNew;
                processImg.Image = bmpOrig;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }