Esempio 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;
        }
Esempio 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);
            }
        }