积极答复者
算术溢出..求帮助..

问题
-
If lyp = True Then Dim myBitmap As New Bitmap(PictureBox1.Size.Width, PictureBox1.Size.Height) Dim image As Image = System.Drawing.Image.FromFile(OpenFileDialog1.FileName) Dim height As Integer = image.Height Dim width As Integer = image.Width For y As Integer = 0 To height - 2 For x As Integer = 0 To width - 2 myBitmap = PictureBox1.Image Dim clr As Color = myBitmap.GetPixel(x, y) Dim clr2 As Color = myBitmap.GetPixel(x + 1, y + 1) Dim r As Double = 0 Dim g As Double = 0 Dim b As Double = 0 r = Math.Abs(clr.R - clr2.R + 128) g =Math.Abs( clr.G - clr2.G + 128) b =Math.Abs( clr.B - clr2.B + 128) If (r > 255) Then r = 255 End If If (r < 0) Then r = 0 End If If (g > 255) Then g = 255 End If If (g < 0) Then g = 0 End If If (b > 255) Then b = 255 End If If (b < 0) Then b = 0 End If myBitmap.SetPixel(x, y, Color.FromArgb(r, g, b)) Next Next PictureBox1.Image = myBitmap End If
死活就是溢出,求帮助啊..Visual Basic 初学者 望关照!
答案
-
您好,
我注意到 你的myBitmap的大小是picturebox的大小,不是image的大小,但是你在设像素点的时候用的是image的index。当image比picturebox大的时候,必然会索引出界。
我看到你是想将image复制到bitmap,如果是这样的话,我建议你直接用这个构造方法:http://msdn.microsoft.com/en-us/library/0wh0045z.aspx
希望清楚了。
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Mike FengModerator 2012年10月9日 5:31
- 已标记为答案 Mike FengModerator 2012年10月17日 10:29
-
Dim height As Integer =
myBitmap
.Height Dim width As Integer =myBitmap
.Width- 已建议为答案 Mike FengModerator 2012年10月9日 5:31
- 已标记为答案 Mike FengModerator 2012年10月17日 10:29
全部回复
-
您好,
我注意到 你的myBitmap的大小是picturebox的大小,不是image的大小,但是你在设像素点的时候用的是image的index。当image比picturebox大的时候,必然会索引出界。
我看到你是想将image复制到bitmap,如果是这样的话,我建议你直接用这个构造方法:http://msdn.microsoft.com/en-us/library/0wh0045z.aspx
希望清楚了。
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Mike FengModerator 2012年10月9日 5:31
- 已标记为答案 Mike FengModerator 2012年10月17日 10:29
-
Excuse Me,but....this code works perfectly...
但是...这个代码没问题吖..
If lyp = True Then Dim myBitmap As New Bitmap(PictureBox1.Size.Width, PictureBox1.Size.Height) Dim image As Image = System.Drawing.Image.FromFile(OpenFileDialog1.FileName) Dim height As Integer = image.Height Dim width As Integer = image.Width For y As Integer = 0 To height - 1 For x As Integer = 0 To width - 1 myBitmap = PictureBox1.Image Dim clr As Color = myBitmap.GetPixel(x, y) clr = Color.FromArgb(225, 255 - clr.R, 255 - clr.G, 255 - clr.B) myBitmap.SetPixel(x, y, clr) Next Next PictureBox1.Image = myBitmap
..求解..
Visual Basic 初学者 望关照!
-
你的myBitmap的大小是picturebox的大小,不是image的大小,但是你在设像素点的时候用的是image的index。当image比picturebox大的时候,必然会索引出界。
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Dim height As Integer =
myBitmap
.Height Dim width As Integer =myBitmap
.Width- 已建议为答案 Mike FengModerator 2012年10月9日 5:31
- 已标记为答案 Mike FengModerator 2012年10月17日 10:29