Fehlerbehebung Hilfe! Anfänger windows.forms
Verfasst: So Sep 08, 2019 2:32 am
hi,
ich hab ein kleines programm geschrieben welches nichtmal im ansatz funktioniert. ich kann leider den fehler nicht finden. ziel ist es einem graustufenbild farbe zu geben ohne die graustufen zu verändern.
Danke für eure Hilfe !
Gruß
ich hab ein kleines programm geschrieben welches nichtmal im ansatz funktioniert. ich kann leider den fehler nicht finden. ziel ist es einem graustufenbild farbe zu geben ohne die graustufen zu verändern.
Code: Alles auswählen
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace training
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button2_Click(object sender, EventArgs e)
{
try
{
// grayscale bild welches farbig werden soll
Bitmap Gray = new Bitmap(@"C:\Users\Dell\Pictures\Gray.jpg", true);
// farbiges bild (quasi farb-pallette für das grayscale bild)
Bitmap Color = new Bitmap(@"C:\Users\Dell\Pictures\Color.jpg", true);
// Ausgabe vom grayscale img in picturebox
pictureBox1.Image = Gray;
int x = 0;
int y = 0;
int x2 = 0;
int y2 = 0;
// durchläuft pixel grayscale bild
for (x = 0; x < Gray.Width; x++)
{
for (y = 0; y < Gray.Height; y++)
{
// findet Graustufenwert für grayscale bild und speichert ihn in variable
Color pixelGray = Gray.GetPixel(x, y);
float grayValue = (pixelGray.R + pixelGray.G + pixelGray.B) / 3;
int grayValueRound = (int)Math.Round(grayValue);
// durchläuft pixel farbiges bild
for (x2 = 0; x2 < Color.Width ; x2++)
{
for (y2 = 0; y2 < Color.Height; y2++)
{
// findet Graustufenwert für farbiges bild und speichert ihn in variable
Color pixelColor = Color.GetPixel(x2, y2);
float colorValue = (pixelColor.R + pixelColor.G + pixelColor.B) / 3;
int colorValueRound = (int)Math.Round(colorValue);
// gibt dem grayscale pixel farbe bei selbem Value
if (grayValueRound == colorValueRound)
{
Gray.SetPixel(x, y, pixelColor);
}
}
}
}
}
pictureBox1.Image = Gray;
Gray.Save("C:Pictures\\Color.bmp");
MessageBox.Show("THE END");
}
catch (System.IO.FileNotFoundException)
{
MessageBox.Show("There was an error opening the bitmap." +
"Please check the path.");
}
}
}
}
Gruß