| 【】Top
 
 【】VB.NET
 【】VB6.0
 
 【】メールマガジンの購読
 【】メールマガジンの解除
 
 
 
 
 
 
 【】会社概要
 
 【】お問い合わせ
 
 
 姉妹サイト「バーチャルコネクション!」はこちらです。
 
 姉妹サイト「七福神のメールでビンゴ!」はこちらです。
 
 
   
 ●24時間365日の安心をあなたにAT-LINK専用サーバ・サービスお勧めのサーバです。
 
 
 | 
 
               
                |  |  |  |   
                |  | 
   
 
   
    | 
  
        http://anetm.com/dev/d.cgi?SC=DTDTL&o=O7l 
        
  
                 
               
                 
                  | 画像を拡大縮小させたり、回転して表示する |   
                  | 
 |   
                  | .NET でも、画像を拡大縮小させたり、回転させることが可能です。 
 この機能を使えば、簡単に、
 アニメーション効果機能のあるアプリケーションや、
 プレビューを簡単に作成できます。
 
 
 フォームに次の様なコードを記述します
 
 
 -----------VB.NETコーディングここから-------------------
 
 
 1.フォームに、ラベルコントロール、
 テキストボックスコントロール、
 ボタンコントロール、
 ピクチャボックスコントロールを配置します。
 下記は、デフォルトのオブジェクトの名前と配置を示しています。
 
 ┏━━━━━━━━━━━━━━┓┏━━━━┓
 ┃Label1                      ┃┃Button1 ┃
 ┗━━━━━━━━━━━━━━┛┗━━━━┛
 ┏━━━━━━━━━━━━━━┓┏━━━━┓
 ┃TextBox1                    ┃┃Button2 ┃
 ┗━━━━━━━━━━━━━━┛┗━━━━┛
 ┏━━━━━━━━━━━━━━━━━━━━┓
 ┃PictureBox1                             ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┗━━━━━━━━━━━━━━━━━━━━┛
 
 
 2.ラベルコントロール
 Label1 text プロパティに
 「画像のURLを入力して下さい」と記述します。
 
 さらに、ボタンコントロールの
 Button1 text プロパティに「回転」と記述します。
 
 さらに、ボタンコントロールの
 Button2 text プロパティに「中断」と記述します。
 
 さらに、テキストコントロールの
 TextBox1 text プロパティを空白にします。
 
 ※説明用のためです。必須ではありません。
 
 ┏━━━━━━━━━━━━━━┓┏━━━━┓
 ┃画像のURLを入力して下さい   ┃┃回転    ┃
 ┗━━━━━━━━━━━━━━┛┗━━━━┛
 ┏━━━━━━━━━━━━━━┓┏━━━━┓
 ┃                            ┃┃中断    ┃
 ┗━━━━━━━━━━━━━━┛┗━━━━┛
 ┏━━━━━━━━━━━━━━━━━━━━┓
 ┃PictureBox1                             ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┃                                        ┃
 ┗━━━━━━━━━━━━━━━━━━━━┛
 
 
 3.ボタンコントロールをダブルクリックして、
 ボタンのクリックイベントの編集を開始して、
 フォームの宣言部に、次のコードを記述します。
 
 Imports System.Net
 Imports System.IO
 
 
 さらに、次のコードを記述します。
 
 
 Dim intEnd As Boolean
 
 Private Sub Button1_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles Button1.Click
 
 Dim strUrl As String = TextBox1.Text
 If strUrl.Length = 0 Then
 MsgBox("画像までのURLを入力してください")
 Exit Sub
 End If
 
 Dim WebC As WebClient = New WebClient
 Dim MyStream As Stream = WebC.OpenRead(strUrl)
 Dim MyBitmap As Bitmap = New Bitmap(MyStream)
 
 MyStream.Close()
 
 Dim intWidth As Integer = MyBitmap.Width / 2
 Dim intHeight As Integer = MyBitmap.Height / 2
 Dim MyBitmap2 As Bitmap = New Bitmap(MyBitmap, intWidth, _
 intHeight)
 
 
 Dim Gr As Graphics          'グラフィックオブジェクト
 Dim sglGrangle As Single    'アングル(角度)
 
 '描画先のピクチャーボックスに、
 'グラフィックオブジェクトを作成()
 Gr = PictureBox1.CreateGraphics()
 
 
 
 'アングルを初期化
 sglGrangle = 0
 
 'テキストボックスに入力した文字列を
 'ピクチャーボックスに回転しながら描画します
 Do
 With Gr
 
 
 Dim sgld As Double = sglGrangle / (180 / Math.PI)
 Dim sglx As Single = PictureBox1.Width / 2
 Dim sgly As Single = PictureBox1.Height / 2
 Dim sglx1 As Single = _
 sglx + MyBitmap2.Width * CType(Math.Cos(sgld), _
 Single)
 Dim sgly1 As Single = _
 sgly + MyBitmap2.Width * CType(Math.Sin(sgld), _
 Single)
 Dim sglx2 As Single = _
 sglx - MyBitmap2.Height * CType(Math.Sin(sgld), _
 Single)
 Dim sgly2 As Single = _
 sgly + MyBitmap2.Height * CType(Math.Cos(sgld), _
 Single)
 Dim destinationPoints() As PointF = _
 {New PointF(sglx, sgly), _
 New PointF(sglx1, sgly1), _
 New PointF(sglx2, sgly2)}
 
 PictureBox1.Invalidate()
 
 
 '画像を表示
 Gr.DrawImage(MyBitmap2, destinationPoints)
 
 
 End With
 
 
 '回転角度のステップ
 sglGrangle = sglGrangle + 1
 '360度を越える場合は、処理を抜けます
 If sglGrangle > 360 Then sglGrangle = 0
 
 
 System.Windows.Forms.Application.DoEvents()
 If intEnd Then
 intEnd = False
 Exit Do
 End If
 
 Loop
 
 
 End Sub
 
 Private Sub Button2_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles Button2.Click
 
 intEnd = True
 
 End Sub
 
 
 
 
 4.ビルドして実行します。
 
 5.フォームに表示された
 テキストボックスに、
 「 http://anetm.com/m/images/head2.gif 」と入力します。
 
 6.フォームに表示された
 「回転」ボタンを押すと、取得した画像が
 回転しながら描画されます。
 
 
 
 -----------VB.NETコーディングここまで-------------------
 
 回転の中心を変えたり、回転角度を縮小したりすることも
 可能です。.NETでも画像の合成や変形なども行えます。
 
 
 |  
  
             
   
 Copyright(c)2001-2004 Ai Net Makoto 記事・情報の無断転載を禁止します。  |  |  |   
                |  |  |  |  |