Results 1 to 2 of 2

Thread: Problem (converting Vb6 code to .net) that manipulates images [resolved by me]

  1. #1

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172

    Problem (converting Vb6 code to .net) that manipulates images [resolved by me]

    I am new to .net but want to use this vb6 code in vb.net (no success ofcourse) but what to change and all? :s

    what it does is convert a grayscale image to have an rgb value and make it a real color like a more red like color or so.

    VB Code:
    1. Public layout_color(2) As Integer
    2. Public layout_red As Integer
    3. Public layout_green As Integer
    4. Public layout_blue As Integer
    5.  
    6. Public Sub obtainRGB(cValue)
    7. layout_color(0) = Int(cValue / 65536) + layout_red
    8. cValue = cValue Mod 65536
    9. layout_color(1) = Int(cValue / 256) + layout_green
    10. cValue = cValue Mod 256
    11. layout_color(2) = cValue + layout_blue
    12. If layout_color(0) < 0 Then layout_color(0) = 0: If layout_color(0) > 255 Then layout_color(0) = 255
    13. If layout_color(1) < 0 Then layout_color(1) = 0: If layout_color(1) > 255 Then layout_color(0) = 255
    14. If layout_color(2) < 0 Then layout_color(2) = 0: If layout_color(2) > 255 Then layout_color(2) = 255
    15. End Sub
    16.  
    17. Public Sub layout_convert(red As Integer, green As Integer, blue As Integer)
    18. Dim X As Long: Dim Y As Long
    19. layout_red = red: layout_green = green: layout_blue = blue
    20. For Y = 0 To cmd_image_orig.Height - 1
    21.     For X = 0 To cmd_image_orig.Width - 1
    22.         obtainRGB (cmd_image_orig.Point(X, Y))
    23.         cmd_image_new.PSet (X, Y), RGB(layout_color(0), layout_color(1), layout_color(2))
    24.         DoEvents
    25.     Next X
    26. Next Y
    27. end sub

    the above code work 100% correctly but how can i make such a thing in .net? this is how far i got ...


    VB Code:
    1. Public layout_color(2) As Integer
    2.     Public layout_red As Integer
    3.     Public layout_green As Integer
    4.     Public layout_blue As Integer
    5.     Dim myBitmap As System.Drawing.Bitmap
    6.     Dim tmpColor As System.Drawing.Color
    7.     Public Sub obtainRGB(ByVal cValue)
    8.         layout_color(0) = Int(cValue / 65536) + layout_red
    9.         cValue = cValue Mod 65536
    10.         layout_color(1) = Int(cValue / 256) + layout_green
    11.         cValue = cValue Mod 256
    12.         layout_color(2) = cValue + layout_blue
    13.         If layout_color(0) < 0 Then layout_color(0) = 0 : If layout_color(0) > 255 Then layout_color(0) = 255
    14.         If layout_color(1) < 0 Then layout_color(1) = 0 : If layout_color(1) > 255 Then layout_color(0) = 255
    15.         If layout_color(2) < 0 Then layout_color(2) = 0 : If layout_color(2) > 255 Then layout_color(2) = 255
    16.    '// From here on i am stuck
    17.  
    18.     End Sub
    19.  
    20.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    21.         Dim X As Long : Dim Y As Long
    22.  
    23.         layout_red = 255 : layout_green = 0 : layout_blue = 0
    24.         For Y = 0 To Picture1.Height - 1
    25.             For X = 0 To Picture1.Width - 1
    26.                 tmpColor = myBitmap.GetPixel(X, Y)
    27.                ' from here i am stuck too
    28.                 myBitmap.SetPixel(X, Y, tmpColor)
    29.             Next X
    30.         Next Y
    31.   End Sub
    32. but does not work at all
    Last edited by Ultimasnake; Sep 18th, 2003 at 08:41 AM.
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  2. #2

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    i feel so smart now.. just made it

    is this a nice good vb.net code?


    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         changecolor(100, 0, 0)
    3.     End Sub
    4.  
    5.     Public Function changecolor(ByVal r As Integer, ByVal g As Integer, ByVal b As Integer)
    6.         Dim myBitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(Picture1.Image)
    7.         Dim newbitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(Picture1.Width, Picture1.Height)
    8.         Dim tmpcolor As System.Drawing.Color
    9.         Dim tempr As Integer : Dim tempg As Integer : Dim tempb As Integer
    10.         Dim X As Long : Dim Y As Long
    11.         For Y = 1 To Picture1.Height - 1
    12.             For X = 1 To Picture1.Width - 1
    13.                 tmpColor = myBitmap.GetPixel(X, Y)
    14.                 tempr = tmpcolor.R() + r : tempg = tmpcolor.G() + g : tempb = tmpcolor.B() + b
    15.                 If tempr < 0 Then tempr = 0
    16.                 If tempr > 255 Then tempr = 255
    17.                 If tempg < 0 Then tempg = 0
    18.                 If tempg > 255 Then tempg = 255
    19.                 If tempb < 0 Then tempb = 0
    20.                 If tempb > 255 Then tempb = 255
    21.  
    22.                 newbitmap.SetPixel(X, Y, tmpcolor.FromArgb(tempr, tempg, tempb))
    23.             Next X
    24.         Next Y
    25.         Picture2.Image = newbitmap
    26.     End Function
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

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