borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (way to calculete lcd response time)Next Topic (Calling ini file (problem with code)) New Topic New Poll Post Reply
AndreaVB Forum : API : Get RGB
Poster Message
Takeshi
Level: Protégé

Registered: 08-09-2008
Posts: 8

icon Get RGB

Hello everybody... I'm a newbies. Can any one help me ? I create a image encryption program. The input is the RGB value from that image file. How to get the RGB value at every pixel of a image file? The image file can be any format (not only bmp) that VB's support. The image file loaded from open dialog.
I found getpixel function, but I'm not sure it's correct.
Please.... I need this hurried.... Thanx. GBU    

08-09-2008 at 07:38 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 601
icon Re: Get RGB

Once the image is loaded inside a picture control you can use Point function to get the color of a pixel

Picture1.Point(xcoord,ycoord)

returns the long color of the pixel at xcoord,ycoord

let me know if you need more help

____________________________
AndreaVB

10-11-2008 at 10:02 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Takeshi
Level: Protégé

Registered: 08-09-2008
Posts: 8
icon Re: Get RGB

Thakns... One question again. I was make a code to insert that RGB values to an array, but an error appear "subscript out of range". Can u help me ?

I make this code before i receive your message. I try to use getpixel anyway, but still not sure i get the color because that error message  :

Private Sub Command2_Click()
    Dim intX As Integer
    Dim intY As Integer
    Dim n As Integer
    Dim M As Integer
    Dim a() As Integer
    Dim b() As Integer
    Dim C() As Integer
    Dim col As Long
    Dim RGB() As Byte
    Dim i As Integer
    
    
    n = 0
    M = 0
    
    With Picture1.Picture
        intY = ScaleY(.Height, vbHimetric, vbPixels)
        intX = ScaleX(.Width, vbHimetric, vbPixels)
        Me.Label13 = "height : " & intY & ", Width : " & intX
        i = 0
        For n = 0 To intX
            For M = 0 To intY
                col = GetPixel(Picture1.hDC, n, M)
                a(i) = col And &HFF       ('this line is error')
                'b = (col \ 256) Mod 256
                b(i) = (col \ &H100) And &HFF
                'c = (col \ 256 \ 256)
                C(i) = (col \ &H10000) And &HFF
                i = i + 1
                M = M + 1
            Next
            n = n + 1
            
        Next
    End With
End Sub

Thanks for your help. GBU.


[Edited by admin on 12-11-2008 at 02:53 PM GMT]

11-11-2008 at 09:29 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 601
icon Re: Get RGB

you are receiving this error because you did not dimension a(), b() and c() try this:




Dim a() As Integer
    Dim b() As Integer
    Dim C() As Integer
    Dim col As Long
    Dim RGB() As Byte
    Dim i As Integer
    
    
    n = 0
    M = 0
    
    With Picture1.Picture
        intY = ScaleY(.Height, vbHimetric, vbPixels)
        intX = ScaleX(.Width, vbHimetric, vbPixels)
        redim a(0 to (intX+1)*(intY+1))
        redim b(0 to (intX+1)*(intY+1))
        redim c(0 to (intX+1)*(intY+1))


and then the rest of your code should work fine

let me know

____________________________
AndreaVB

12-11-2008 at 02:00 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Takeshi
Level: Protégé

Registered: 08-09-2008
Posts: 8
icon Re: Get RGB

It's not work, instead appear an another error 'overflow' at redim statement.

16-11-2008 at 04:13 PM
View Profile Send Email to User Show All Posts | Quote Reply
Takeshi
Level: Protégé

Registered: 08-09-2008
Posts: 8
icon Re: Get RGB

FinaIly, i have found the answer of that error. I change data type of intX or intY to long type. Can one or both. I don't know why must like that (if u can explain me, i so thanks u ).
So, next.
If i change the value of all array of RGB values, then i want to save again / create the changed RGB values to an image file (bmp, jpg, gif, etc), what should i do ? Or ,what codes i must write ?
I wait for your answer. Thanks. GBU.

16-11-2008 at 06:34 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : API : Get RGB
Previous Topic (way to calculete lcd response time)Next Topic (Calling ini file (problem with code)) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder