Last active
June 16, 2021 12:58
-
-
Save dj1711572002/1bfacc9e6574816de848dfc1fa12a608 to your computer and use it in GitHub Desktop.
VB.NET_Graph_Triming_Test_TrimPosition set with SlideBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Form1 | |
Dim totalPlot As Bitmap | |
Dim tg As Graphics | |
Private Sub plotSlider(ByVal startNo As Integer) | |
'画像の一部を切り取って(トリミングして)表示する | |
Debug.Print(startNo) | |
Dim timeScale As Integer = 3 | |
Dim canvas As New Bitmap(PictureBox1.Width, PictureBox1.Height) 'W=400,H=240 | |
Dim g As Graphics = Graphics.FromImage(canvas) | |
Dim srcRect As New Rectangle(startNo, 0, 400, 210) | |
'描画する部分の範囲を決定する。ここでは、位置(0,0)、大きさソース切取りサイズで描画する | |
Dim desRect As New Rectangle(0, 0, srcRect.Width, srcRect.Height) | |
'画像の一部を描画する | |
g.DrawImage(totalPlot, desRect, srcRect, GraphicsUnit.Pixel) | |
'Graphicsオブジェクトのリソースを解放する | |
g.Dispose() | |
'PictureBox1に表示する | |
PictureBox2.Image = canvas | |
End Sub | |
Private Sub HScrollBar1_ValueChanged(sender As Object, e As EventArgs) Handles HScrollBar1.ValueChanged | |
'maximum=1200 minimum=0 | |
Dim slideVal As Integer = HScrollBar1.Value | |
plotSlider(slideVal) | |
TextBox1.Text = CStr(slideVal) | |
End Sub | |
'元グラフを作成する | |
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click | |
totalPlot = New Bitmap(PictureBox1.Width * 3, PictureBox1.Height) | |
tg = Graphics.FromImage(totalPlot) | |
Dim i As Integer | |
For i = 1 To PictureBox1.Width * 3 | |
Dim px As Integer = i | |
Dim py As Integer = Math.Sin(Math.PI / 30 * i) * 100 * (i / 1200) + 100 | |
tg.FillEllipse(Brushes.Red, px, py, 4, 4) | |
Next i | |
PictureBox1.Image = totalPlot | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment