I am testing out applying interesting effects to photos...
One effect I have invented is make the image only have 4 colors in it... red (at 255), green at (255), blue at (255) and black at (0)
Basically calculations are done for each pixel and then sets each pixel depending on the color which is the strongest.
For example a pixel with r = 140 g = 120 b = 100
The highest color intensity is red so it would become r = 255 g = 0 b = 0
The only problem is speed...
The only object on the form is a picturebox.
Here is my code:
***How can I speed it up to be finished basically instantly...
***Also the form freezes and is unusable while the operation is in process... is there a way to allow the form to still be used such as moved around while its working?
***Lastly... how come I only see the result at the end and not see it slowly converting the picture... since I am using the sync method (my own) to constantly update the bitmap throughout the whole process... but it only shows the result at the end
One effect I have invented is make the image only have 4 colors in it... red (at 255), green at (255), blue at (255) and black at (0)
Basically calculations are done for each pixel and then sets each pixel depending on the color which is the strongest.
For example a pixel with r = 140 g = 120 b = 100
The highest color intensity is red so it would become r = 255 g = 0 b = 0
The only problem is speed...
The only object on the form is a picturebox.
Here is my code:
VB.NET:
Public Class Form1
Dim mybitmap As New Bitmap(56, 456)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFileDialog1.ShowDialog()
mybitmap = New Bitmap(OpenFileDialog1.FileName)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Dock = DockStyle.Fill
sync()
End Sub
Private Sub sync()
PictureBox1.Image = mybitmap
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
For y As Integer = 0 To mybitmap.Height - 1
For x As Integer = 0 To mybitmap.Width - 1
Dim red, green, blue As Integer
red = mybitmap.GetPixel(x, y).R.ToString
green = mybitmap.GetPixel(x, y).G.ToString
blue = mybitmap.GetPixel(x, y).B.ToString
If red > green And red > blue Then
red = 255
blue = 0
green = 0
ElseIf green > blue And green > red Then
green = 255
red = 0
blue = 0
ElseIf blue > red And blue > green Then
blue = 255
red = 0
green = 0
Else
blue = 0
red = 0
green = 0
End If
mybitmap.SetPixel(x, y, Color.FromArgb(red, green, blue))
sync()
Dim per As Integer
per = (y / mybitmap.Height) * 100
Me.Text = per & "% Complete"
Next
Next
End Sub
End Class
***How can I speed it up to be finished basically instantly...
***Also the form freezes and is unusable while the operation is in process... is there a way to allow the form to still be used such as moved around while its working?
***Lastly... how come I only see the result at the end and not see it slowly converting the picture... since I am using the sync method (my own) to constantly update the bitmap throughout the whole process... but it only shows the result at the end
Last edited: