Exemplo n.º 1
0
        private void TransformbyOrigin()
        {
            int    angle = trackBar1.Value;
            int    move_x = Decimal.ToInt32(TranslationX.Value), move_y = Decimal.ToInt32(TranslationY.Value);
            double scale = ScaleBar.Value / 10.0;


            Bitmap image       = new Bitmap(Image.FromFile(this.filename));
            Bitmap createImage = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            // 原点に移動
            int biasX = createImage.Width / 2 - this.ImageSize.X / 2;
            int biasY = createImage.Height / 2 - this.ImageSize.Y / 2;

            // アフィンマトリックスを作成
            AffineMatrix aMatrix = new AffineMatrix();

            aMatrix.SetMatrix(angle, move_x + biasX, move_y + biasY, scale);

            for (int y = 0; y < createImage.Height; y++)
            {
                for (int x = 0; x < createImage.Width; x++)
                {
                    Point nPoint = new Point(x, y);
                    Point oPoint = aMatrix.CalcInverseMatrix(nPoint);
                    if (this.IsOutOfRange(oPoint.X, oPoint.Y, image.Width, image.Height))
                    {
                        continue;
                    }
                    createImage.SetPixel(x, y, image.GetPixel(oPoint.X, oPoint.Y));
                }
            }
            pictureBox1.Image = createImage;
        }
Exemplo n.º 2
0
        private void ImageReset()
        {
            try
            {
                Bitmap image       = new Bitmap(Image.FromFile(this.filename));
                Bitmap createImage = new Bitmap(pictureBox1.Width, pictureBox1.Height);

                int move_x = createImage.Width / 2, move_y = createImage.Height / 2;
                // 中心点に移動
                int biasX = image.Width / 2;
                int biasY = image.Height / 2;
                this.ImageSize = new Point(image.Width, image.Height);

                // アフィンマトリックスを作成
                AffineMatrix aMatrix = new AffineMatrix();
                aMatrix.SetMatrix(0, move_x - biasX, move_y - biasY, 1.0);

                for (int y = 0; y < createImage.Height; y++)
                {
                    for (int x = 0; x < createImage.Width; x++)
                    {
                        Point nPoint = new Point(x - biasX, y - biasY);
                        Point oPoint = aMatrix.CalcInverseMatrix(nPoint);
                        if (this.IsOutOfRange(oPoint.X + biasX, oPoint.Y + biasY, image.Width, image.Height))
                        {
                            continue;
                        }
                        createImage.SetPixel(x, y, image.GetPixel(oPoint.X + biasX, oPoint.Y + biasY));
                    }
                }
                pictureBox1.Image = createImage;
            }
            catch (Exception ex)
            {
                MessageBox.Show("イメージが読み込めません", "LOAD ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private Point MoveInArea(int x, int y, int mx, int my, AffineMatrix Matrix)
        {
            Point[] edge = new Point[4];
            // 時計回り
            edge[0].X = x; edge[0].Y = y;
            edge[1].X = mx; edge[1].Y = y;
            edge[2].X = mx; edge[2].Y = my;
            edge[3].X = x; edge[3].Y = my;

            for (int i = 0; i < edge.Length; i++)
            {
                edge[i] = Matrix.CalcMatrix(edge[i]);
            }

            int[] arrayX = new int[4];
            int[] arrayY = new int[4];
            for (int i = 0; i < edge.Length; i++)
            {
                arrayX[i] = edge[i].X;
                arrayY[i] = edge[i].Y;
            }

            return(new Point(-1 * this.GetMin(arrayX), -1 * this.GetMin(arrayY)));
        }