VB.netで画像のRGB値を変更したく、
赤に128を足すプログラムを作成しようとしているのですが、
VB.net全くの初心者であるため、プログラムの書き方が分かりません。
VB.net
1 2Public Function GetPixel ( 3 x As Integer, 4 y As Integer 5) As Color 6'Imports System.Drawing 7 8''' <summary> 9''' 指定した画像の色を補正する 10''' </summary> 11''' <param name="img">補正する画像</param> 12''' <param name="rValue">赤の増加値(-255~255)</param> 13''' <param name="gValue">緑の増加値(-255~255)</param> 14''' <param name="bValue">青の増加値(-255~255)</param> 15Public Shared Sub CorrectColorImage( _ 16 ByVal img As Bitmap, ByVal rValue As Integer, _ 17 ByVal gValue As Integer, ByVal bValue As Integer) 18 For x As Integer = 0 To img.Width - 1 19 For y As Integer = 0 To img.Height - 1 20 '指定したピクセルの色を取得する 21 Dim c As Color = img.GetPixel(x, y) 22 '新しい色を計算する 23 Dim newR As Integer = Math.Max(0, Math.Min(255, c.R + rValue)) 24 Dim newG As Integer = Math.Max(0, Math.Min(255, c.G + gValue)) 25 Dim newB As Integer = Math.Max(0, Math.Min(255, c.B + bValue)) 26 '新しい色を設定する 27 img.SetPixel(x, y, Color.FromArgb(c.A, newR, newG, newB)) 28 Next 29 Next 30End Sub 31 32'PictureBox1のClickイベントハンドラ 33Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As EventArgs) _ 34 Handles PictureBox1.Click 35 '色補正をする画像 36 Dim img As New Bitmap("C:\test\1.png") 37 '赤を128増加させる 38 CorrectColorImage(img, 128, 0, 0) 39 'PictureBox1に表示 40 If Not PictureBox1.Image Is Nothing Then 41 PictureBox1.Image.Dispose() 42 End If 43 PictureBox1.Image = img 44End Sub 45
このまま打っても
「名前空間のステートメントが無効です。」
というエラーがたくさん表示されるばかりです。
エラーの意味も全くわかりません。。
これに何を付け足せばよいのでしょうか。
VB.netは、Javaなどのように保存するファイル名も決まっていたりするのでしょうか?
また、赤だけでなく、緑、青も一気に変更するにはどのように書けばよいのでしょうか。。
どなたか教えてください。