/// <summary> /// アフィン変換実行ボタンのクリックイベント /// </summary> /// <param name="sender">オブジェクト</param> /// <param name="e">イベントのデータ</param> private void OnClickBtnGo(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(m_strOpenFileName)) { return; } CAffineInfo affineInfo = new CAffineInfo(); if (!IsEmpty(textBoxTx.Text)) { affineInfo.Translate.Tx = float.Parse(textBoxTx.Text); } if (!IsEmpty(textBoxTy.Text)) { affineInfo.Translate.Ty = float.Parse(textBoxTy.Text); } if (!IsEmpty(textBoxSx.Text)) { affineInfo.Scale.Sx = float.Parse(textBoxSx.Text); } if (!IsEmpty(textBoxSy.Text)) { affineInfo.Scale.Sy = float.Parse(textBoxSy.Text); } if (!IsEmpty(textBoxRotate.Text)) { affineInfo.Rotate.Angle = float.Parse(textBoxRotate.Text); } pictureBox.Image = Affine(affineInfo); }
/// <summary> /// アフィン変換 /// </summary> /// <param name="_affineInfo">アフィン変換情報</param> /// <returns>アフィン変換のイメージ</returns> public Image Affine(CAffineInfo _affineInfo) { float fTx = _affineInfo.Translate.Tx; float fTy = _affineInfo.Translate.Ty; float fSx = _affineInfo.Scale.Sx; float fSy = _affineInfo.Scale.Sy; float fAngle = _affineInfo.Rotate.Angle; Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height); Graphics graphics = Graphics.FromImage(bitmap); Image image = Image.FromFile(m_strOpenFileName); graphics.ResetTransform(); graphics.TranslateTransform(fTx, fTy, System.Drawing.Drawing2D.MatrixOrder.Append); graphics.ScaleTransform(fSx, fSy); graphics.RotateTransform(fAngle, System.Drawing.Drawing2D.MatrixOrder.Append); graphics.DrawImage(image, new Rectangle(0, 0, pictureBox.Width, pictureBox.Height)); image.Dispose(); graphics.Dispose(); return(bitmap); }