Results 1 to 24 of 24

Thread: [RESOLVED] [VB6] API DIBs - Change Image Colors

Threaded View

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Resolved [RESOLVED] [VB6] API DIBs - Change Image Colors

    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:
    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
    now heres the project....
    i don't know why these error
    can anyone help me fix the error?
    thanks
    Attached Files Attached Files
    Last edited by joaquim; Nov 18th, 2009 at 04:34 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width