環境:visual studio 2010 (VB.NET) 現在上記環境にて、画像処理プログラムを作成しています。 概要は、画像表示→画像の切取り、移動、貼付け→加工後画像保存 というような流れになります。 まず、Form上には、Panelの上にPictureBox乗せたものが2つ配置してあります。 表示する画像は、素材画像と、加工先画像の2つです。 また、切取った画像を表示するためにPictureBoxがもう1つあります。 画像はPictureBoxよりも大きく、画像はあらかじめ縮小させて表示しています。 素材画像は、拡大縮小、切取りができるようになっていて 切取った画像は加工先画像へ移動させて貼付けるのですが、 拡大縮小した画像からでも、 加工先の拡大率に合わせてというか、、 原寸大の大きさでというか、、(でも画面の見た目は拡大縮小のまま) 画像を切取り、貼付けたいのです。 ちょっと分りづらいとは思いますが、現状では完成イメージが違います。 また、切取り画像移動後の加工先画像への貼付けもうまく実装できません。 現状ソースを開示します。 *********************************************************************************************************************************************************** Public Class test Private DefaultImage As Bitmap Private BaseImage As Bitmap #Region " フォーム初期処理 " Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PictureBox1.SizeMode = PictureBoxSizeMode.Zoom PictureBox2.SizeMode = PictureBoxSizeMode.Zoom DefaultImage = New Bitmap("C:\TMP\001.tif") BaseImage = New Bitmap("C:\TMP\Base.tif") 'PictureBoxに表示する PictureBox1.Image = New Bitmap(DefaultImage, PictureBox1.Width, PictureBox1.Height) PictureBox2.Image = New Bitmap(BaseImage, PictureBox2.Width, PictureBox2.Height) PictureBox3.Height = 0 End Sub #End Region #Region " 拡大縮小 " Private Sub PictureBox1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel Try PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize If e.Delta > 0 Then '拡大イメージを作成する Zoom(PictureBox1, DefaultImage, 1.01) Else '縮小イメージを作成する Zoom(PictureBox1, DefaultImage, 0.99) End If Catch ex As ArgumentException MsgBox(ex.Message) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Zoom(ByRef PictBox As PictureBox, ByVal DefImg As Bitmap, ByVal ZoomRatio As Double) Dim bmp As New Bitmap(PictBox.Image, PictBox.Image.Width * ZoomRatio, PictBox.Image.Height * ZoomRatio) '拡大縮小したイメージをセットする PictBox.Image = bmp bmp.Dispose() bmp = Nothing '描画先とするImageオブジェクトを作成する() Dim can As New Bitmap(PictBox.Width, PictBox.Height) 'ImageオブジェクトのGraphicsオブジェクトを作成する Dim g As Graphics = Graphics.FromImage(can) '補間方法として高品質双三次補間を指定する g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic g.DrawImage(DefImg, 0, 0, PictBox.Width, PictBox.Height) 'スケーリングしたイメージをセットする PictBox.Image = can End Sub #End Region ↓↓続く
↧