VB轉VB.NET問題

看板Programming作者時間18年前 (2007/01/18 15:01), 編輯推噓1(104)
留言5則, 1人參與, 最新討論串1/1
各位大大 小弟把VB程式轉成VB.NET 但轉完後,好像是語法的關係 變成無法執行 好像是這行程式的關係Imagetemp = Picture1.hdc 不知道VB.NET的語法是怎麼寫的 請各位大大幫忙,謝謝 詳細程式如下,主要是要將圖片資料讀入,且滑鼠指到的部分會顯示出GRB值 Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Integer) As Intege Const W As Integer = 640 '設定影像寬度 Const H As Integer = 480 '設定影像高度 Dim gray(2, H - 1, W - 1) As Byte Dim RGBtemp As Integer Dim Imagetemp As Integer '*********讀取影像************** Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click Dim j As Object Dim i As Object Dim x As Integer Dim y As Integer '載入影像 Picture1.Image = System.Drawing.Image.FromFile(InputBox("請輸入檔名 (*.bmp或*.jpg)")) '將影像資料(R,G,B值)放入陣列gray中 For i = 0 To H - 1 For j = 0 To W - 1 x = j y = i RGBtemp = GetPixel(Imagetemp, x, y) '取出影像(Imagetemp)之像素座標(x,y)之R,G,B值給變數RGBtemp gray(0, i, j) = Red(RGBtemp) '取出R值 gray(1, i, j) = Green(RGBtemp) '取出G值 gray(2, i, j) = Blue(RGBtemp) '取出B值 Next j Next i End Sub '**********顯示mouse的所在座標並讀取該位置之RGB灰階值************************ Private Sub Picture1_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles Picture1.MouseMove Dim Button As Short = eventArgs.Button \ &H100000 Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000 Dim x As Single = eventArgs.X Dim y As Single = eventArgs.Y Imagetemp = Picture1.hdc RGBtemp = GetPixel(Imagetemp, x, y) Text1.Text = "( " & Str(x) & " , " & Str(y) & " )" '顯示Mouse座標 R_Text.Text = CStr(Red(RGBtemp)) G_Text.Text = CStr(Green(RGBtemp)) B_Text.Text = CStr(Blue(RGBtemp)) End Sub -- ╭─ Origin ─╗ 新綠園 bbs.sa.ncyu.edu.tw ~ κλμ ─┤ ├ Author ╡ 140.130.89.152

01/19 10:00, , 1F
直接用System.Drawing.Image和
01/19 10:00, 1F

01/19 10:03, , 2F
System.Drawing.Graphics.FromImage()
01/19 10:03, 2F

01/19 10:04, , 3F
等GdiPlus Wrapper, 不要call API了...
01/19 10:04, 3F

01/19 10:05, , 4F
啊... 用SetPixel和GetPixel的話要用
01/19 10:05, 4F

01/19 10:06, , 5F
System.Drawing.Bitmap才對...
01/19 10:06, 5F
文章代碼(AID): #15hnim00 (Programming)
文章代碼(AID): #15hnim00 (Programming)