by these page VB Graphics Programming: Part 3 (Advanced API): http://www.tannerhelland.com/vb6/vb-...programming-3/
i build a procedure for change image colors. but by some reason isn't working
The VB6 is closed. but it's showed a Windows error window.
error message: ".... the memory can't be read..." and "...the memory can't be writen".
heres the procedure:
now heres the project....Code:Public Sub SetImageData(ByRef DstPictureBox As PictureBox, ByRef ImageData() As Byte, ByRef OldColor As Long, ByRef NewColor As Long) Dim X As Long, Y As Long For X = 0 To bm.bmHeight - 1 For Y = 0 To bm.bmHeight - 1 If OldColor = RGB(ImageData(2, X, Y), ImageData(1, X, Y), ImageData(0, X, Y)) Then RGBColor = RGBValues(NewColor) ImageData(2, X, Y) = RGBColor.Red ImageData(1, X, Y) = RGBColor.Green ImageData(0, X, Y) = RGBColor.Blue End If Next Y Next X 'Now that we've built the temporary header, we use StretchDIBits to take the data from the ImageData() array and put it into SrcPictureBox using the settings specified in 'bmi' (the StretchDIBits call should be on one continuous line) StretchDIBits DstPictureBox.hDC, 0, 0, bm.bmWidth, bm.bmHeight, 0, 0, bm.bmWidth, bm.bmHeight, ImageData(0, 0, 0), bmi, 0, vbSrcCopy 'Since this doesn't automatically initialize AutoRedraw, we have to do it manually 'Note: always keep AutoRedraw as 'True' when using DIB sections. Otherwise, you WILL get unpredictable results. If DstPictureBox.AutoRedraw = True Then DstPictureBox.Picture = DstPictureBox.Image DstPictureBox.Refresh End If End Sub Private Function RGBValues(Color As Long) As Color 'find the rgb color values of a color Dim ReturnColor As Color With ReturnColor .Red = Fix(Color And 255) .Green = Fix((Color And 65535) / 256) .Blue = Fix(Color / 65536) End With RGBValues = ReturnColor End Function
i don't know why these error
can anyone help me fix the error?
thanks






Reply With Quote