private void RemoveImageBackground(String path, String new_path, String filename) { //Verificações: if (new_path == "") { return; } Bitmap image1 = new Bitmap(path, true); int x, y, opacity; double hue, saturation, value; if (checkBox1.Checked) { opacity = 0; //transparent } else { opacity = 255; //solid } if (checkBox2.Checked == true) { image1 = TranslationTools.ToGrey(image1); } //if (checkBox3.Checked == true) //{ // image1 = TranslationTools.ToBlackAndWhite(image1,opacity); // SaveImage(path, new_path, filename, image1); // image1.Dispose(); // return; //} for (x = 0; x < image1.Width; x++) { for (y = 0; y < image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); //gets the color of each pixel TranslationTools.ColorToHSV(pixelColor, out hue, out saturation, out value); //aqui temos os valores corretos do HSV //nas variaveis hue, saturation e value //MessageBox.Show("hue " + hue + "\nsaturation " + saturation + "\nvalue " + value); if (!RightColor(hue, saturation, value)) { //MessageBox.Show("hue " + hue + "\nsaturation " + saturation + "\nvalue " + value); pixelColor = Color.FromArgb(opacity, 0, 0, 0); image1.SetPixel(x, y, pixelColor); //MessageBox.Show(pixelColor.R + "\n" + pixelColor.G+"\n"+pixelColor.B); } } } //------------- SaveImage(path, new_path, filename, image1); image1.Dispose(); }
private void RemoveImageBackground() { CreateTempImage(NPath, NPath1); //copies the Temp image to another path //now use the new temp Bitmap image1 = new Bitmap(NPath1, true); int x, y, opacity, red, green, blue; if (checkBox1.Checked) { opacity = 0; //transparent } else { opacity = 255; //solid } if (checkBox7.Checked == true) { image1 = TranslationTools.ToGrey(image1); } if (checkBox8.Checked == true) { image1 = TranslationTools.ToBlackAndWhite(image1, opacity, Convert.ToInt32(numericUpDown7.Value)); SaveImage(NPath, image1); image1.Dispose(); return; } bool removeWhite = false; bool removeBlack = false; double hue, saturation, value; if (checkBox2.Checked) { removeWhite = true; } if (checkBox3.Checked) { removeBlack = true; } if (checkBox4.Checked) { red = 255; } else { red = 0; } if (checkBox5.Checked) { green = 255; } else { green = 0; } if (checkBox6.Checked) { blue = 255; } else { blue = 0; } for (x = 0; x < image1.Width; x++) { for (y = 0; y < image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); //gets the color of each pixel if (removeBlack) { if (pixelColor.R < 31 & pixelColor.G < 31 & pixelColor.B < 31) { pixelColor = Color.FromArgb(opacity, red, green, blue); image1.SetPixel(x, y, pixelColor); continue; } } if (removeWhite) { if (pixelColor.A <= 20 | (pixelColor.R >= 235 & pixelColor.G >= 235 & pixelColor.B >= 235)) { pixelColor = Color.FromArgb(opacity, red, green, blue); image1.SetPixel(x, y, pixelColor); continue; } } TranslationTools.ColorToHSV(pixelColor, out hue, out saturation, out value); //aqui temos os valores corretos do HSV //nas variaveis hue, saturation e value //MessageBox.Show("hue " + hue + "\nsaturation " + saturation + "\nvalue " + value); if (!RightColor(hue, saturation, value)) { //MessageBox.Show("hue " + hue + "\nsaturation " + saturation + "\nvalue " + value); pixelColor = Color.FromArgb(opacity, red, green, blue); image1.SetPixel(x, y, pixelColor); //MessageBox.Show(pixelColor.R + "\n" + pixelColor.G+"\n"+pixelColor.B); } } } //------------- SaveImage(NPath, image1); image1.Dispose(); }