heres my code:
i recive these error: "SetPixel is not supported for images with indexed pixel formats."Code:Public Class Form1 Dim imgImage As Bitmap Dim clrOld As Color Dim clrNew As Color Dim blnChangeColor As Boolean Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click ColorDialog1.ShowDialog() PictureBox3.BackColor = ColorDialog1.Color clrNew = ColorDialog1.Color End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpenFileDialog1.ShowDialog() imgImage = Bitmap.FromFile(OpenFileDialog1.FileName) PictureBox1.Image = imgImage End Sub Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick If e.Button = Windows.Forms.MouseButtons.Left Then PictureBox2.BackColor = imgImage.GetPixel(e.X, e.Y) clrOld = PictureBox2.BackColor End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click blnChangeColor = True PictureBox1.Invalidate() End Sub Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint Dim x As Integer = 0 Dim y As Integer = 0 Dim g As Graphics g = PictureBox1.CreateGraphics() If blnChangeColor = True Then For y = 0 To imgImage.Height - 1 For x = 0 To imgImage.Width - 1 If imgImage.GetPixel(x, y) = clrOld Then imgImage.SetPixel(x, y, clrNew) End If Next x Next y g.DrawImage(imgImage, 0, 0, imgImage.Width, imgImage.Height) End If PictureBox1.Invalidate() End Sub End Class
i don't know why these error
can anyone advice me why?






Reply With Quote