Skip to content

Instantly share code, notes, and snippets.

@dj1711572002
Created June 30, 2021 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj1711572002/4e454e0d6f0c1af46d3de7dd3ad88079 to your computer and use it in GitHub Desktop.
Save dj1711572002/4e454e0d6f0c1af46d3de7dd3ad88079 to your computer and use it in GitHub Desktop.
VB.NET Bitmap Trimming linked by plot data
'****************************************************************************************************************
'先端データを読んで切り取りXY座標を制御しながら先端固定モードで描画
'****************************************************************************************************************
Private Sub Bmp1_FixTrim(ByVal SlideVal As Integer, ByVal rNlin As Integer)
'------------------------------------------------------------------------------------------------
'-----HscrollBar値で切り取り前進動画-------------------------------------------------------------
'------------------------------------------------------------------------------------------------
Dim BP1 As New Pen(Color.Red, 1)
Dim BP2 As New Pen(Color.LawnGreen, 1)
Dim BP3 As New Pen(Color.Black)
Dim scrollN As Integer = Math.Truncate(SlideVal / PictureBox1.Width)
Dim cWidth As Integer = SlideVal Mod PictureBox1.Width
Dim sY As Integer
Dim dY As Integer = 0 'desRectのオフセットY位置
Dim rN As Integer = rNlin - Val(TextBox4.Text)
If Fy(SlideVal) > 300 Then
'sY = RY(rN) - 300
sY = CInt(Fy(SlideVal)) - 300
dY = 0
Else
sY = 0
' dY = (300 - RY(rN))
dY = 300 - CInt(Fy(SlideVal))
End If
currentX = CInt(PictureBox1.Width * scrollN)
currentY = sY
' Dim srcRect As New Rectangle(PictureBox1.Width * scrollN,0, cWidth, rangeY) 'Y原点スタート
Dim srcRect As New Rectangle(PictureBox1.Width * scrollN, sY, cWidth, 600) '切り取り部分定義
Dim desRect As New Rectangle(0, dY, srcRect.Width, srcRect.Height)
Debug.Print("StartNo=" + CStr(PictureBox1.Width * scrollN) + ",cWidth=" + CStr(cWidth) + ",SlideVal=" + CStr(SlideVal) + ",rNlin=" + CStr(rNlin) + ",RY=" + CStr(RY(rN)) + ",sY=" + CStr(sY))
Label43.Text = "StartNo=" + CStr(PictureBox1.Width * scrollN) + ",cWidth=" + CStr(cWidth) + ",SlideVal=" + CStr(SlideVal) + ",rNlin=" + CStr(rNlin) + ",RY=" + CStr(RY(rN)) + ",sY=" + CStr(sY) + ",dY=" + CStr(dY)
'Dim desRect As New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Height)
bmap2 = New Bitmap(PictureBox1.Width, PictureBox1.Height)
g2 = Graphics.FromImage(bmap2)
g2.DrawImage(bmap1, desRect, srcRect, GraphicsUnit.Pixel) 'bmap1から指定サイズで切り取ってg2:bmap2へ書き込む
'g2.DrawRectangle(BP1, 0, 0, srcRect.Width, srcRect.Height) '切り取った矩形の外枠を赤線で描画
'g1.Dispose()
g2.Dispose()
'Y軸を180度回転させて上下反転して上を北に変更
bmap2.RotateFlip(RotateFlipType.Rotate180FlipX)
PictureBox1.Image = bmap2 'bmap2を表示
'================================================================
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment