|
-
Sep 18th, 2003, 07:58 AM
#1
Thread Starter
Frenzied Member
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:
Public layout_color(2) As Integer
Public layout_red As Integer
Public layout_green As Integer
Public layout_blue As Integer
Public Sub obtainRGB(cValue)
layout_color(0) = Int(cValue / 65536) + layout_red
cValue = cValue Mod 65536
layout_color(1) = Int(cValue / 256) + layout_green
cValue = cValue Mod 256
layout_color(2) = cValue + layout_blue
If layout_color(0) < 0 Then layout_color(0) = 0: If layout_color(0) > 255 Then layout_color(0) = 255
If layout_color(1) < 0 Then layout_color(1) = 0: If layout_color(1) > 255 Then layout_color(0) = 255
If layout_color(2) < 0 Then layout_color(2) = 0: If layout_color(2) > 255 Then layout_color(2) = 255
End Sub
Public Sub layout_convert(red As Integer, green As Integer, blue As Integer)
Dim X As Long: Dim Y As Long
layout_red = red: layout_green = green: layout_blue = blue
For Y = 0 To cmd_image_orig.Height - 1
For X = 0 To cmd_image_orig.Width - 1
obtainRGB (cmd_image_orig.Point(X, Y))
cmd_image_new.PSet (X, Y), RGB(layout_color(0), layout_color(1), layout_color(2))
DoEvents
Next X
Next Y
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:
Public layout_color(2) As Integer
Public layout_red As Integer
Public layout_green As Integer
Public layout_blue As Integer
Dim myBitmap As System.Drawing.Bitmap
Dim tmpColor As System.Drawing.Color
Public Sub obtainRGB(ByVal cValue)
layout_color(0) = Int(cValue / 65536) + layout_red
cValue = cValue Mod 65536
layout_color(1) = Int(cValue / 256) + layout_green
cValue = cValue Mod 256
layout_color(2) = cValue + layout_blue
If layout_color(0) < 0 Then layout_color(0) = 0 : If layout_color(0) > 255 Then layout_color(0) = 255
If layout_color(1) < 0 Then layout_color(1) = 0 : If layout_color(1) > 255 Then layout_color(0) = 255
If layout_color(2) < 0 Then layout_color(2) = 0 : If layout_color(2) > 255 Then layout_color(2) = 255
'// From here on i am stuck
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim X As Long : Dim Y As Long
layout_red = 255 : layout_green = 0 : layout_blue = 0
For Y = 0 To Picture1.Height - 1
For X = 0 To Picture1.Width - 1
tmpColor = myBitmap.GetPixel(X, Y)
' from here i am stuck too
myBitmap.SetPixel(X, Y, tmpColor)
Next X
Next Y
End Sub
but does not work at all
Last edited by Ultimasnake; Sep 18th, 2003 at 08:41 AM.
-
Sep 18th, 2003, 08:41 AM
#2
Thread Starter
Frenzied Member
i feel so smart now.. just made it 
is this a nice good vb.net code? 
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
changecolor(100, 0, 0)
End Sub
Public Function changecolor(ByVal r As Integer, ByVal g As Integer, ByVal b As Integer)
Dim myBitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(Picture1.Image)
Dim newbitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(Picture1.Width, Picture1.Height)
Dim tmpcolor As System.Drawing.Color
Dim tempr As Integer : Dim tempg As Integer : Dim tempb As Integer
Dim X As Long : Dim Y As Long
For Y = 1 To Picture1.Height - 1
For X = 1 To Picture1.Width - 1
tmpColor = myBitmap.GetPixel(X, Y)
tempr = tmpcolor.R() + r : tempg = tmpcolor.G() + g : tempb = tmpcolor.B() + b
If tempr < 0 Then tempr = 0
If tempr > 255 Then tempr = 255
If tempg < 0 Then tempg = 0
If tempg > 255 Then tempg = 255
If tempb < 0 Then tempb = 0
If tempb > 255 Then tempb = 255
newbitmap.SetPixel(X, Y, tmpcolor.FromArgb(tempr, tempg, tempb))
Next X
Next Y
Picture2.Image = newbitmap
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|