[英]Based on a bitmap input file , show three other bitmap images showing separately the three color components
我有C#的基本知識,但是我有中等C ++技能。 有人要求我幫助他們做作業,在我查閱互聯網之后,我認為我做到了,但是我不知道為什么它不起作用。 分配:編寫一個程序,根據位圖文件輸入生成三個位圖文件,分別顯示三個顏色分量。 編碼 :
private void GetPixel_1(PaintEventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox1.Image);
Bitmap bmp1 = new Bitmap(pictureBox2.Image);
Bitmap bmp2 = new Bitmap(pictureBox3.Image);
Bitmap bmp3 = new Bitmap(pictureBox4.Image);
Color color = new Color();
for (int ii = 0; ii < 200; ii++)
{
for (int jj = 0; jj < 200; jj++)
{
color = bmp.GetPixel(ii, jj);
bmp1.SetPixel(ii, jj, Color.FromArgb(color.R, 0, 0));
bmp2.SetPixel(ii, jj, Color.FromArgb(0, 0,color.B));
bmp3.SetPixel(ii, jj, Color.FromArgb(0, color.G, 0));
}
}
pictureBox2.Image = bmp1;
pictureBox3.Image = bmp2;
pictureBox4.Image = bmp3;
}
我知道這對大多數人來說似乎很基礎,但是如果有人可以幫助我,我仍然會很感激。
class Program
{
static void Main(string[] args)
{
Bitmap bitmap = new Bitmap("Image.bmp");
Bitmap red = new Bitmap(bitmap.Width, bitmap.Height);
Bitmap blue = new Bitmap(bitmap.Width, bitmap.Height);
Bitmap green = new Bitmap(bitmap.Width, bitmap.Height);
for (int x = 0; x < bitmap.Width; x++)
{
for (int y = 0; y < bitmap.Height; y++)
{
Color c = bitmap.GetPixel(x, y);
red.SetPixel(x, y, Color.FromArgb(c.R, 0, 0));
blue.SetPixel(x, y, Color.FromArgb(0, 0, c.B));
green.SetPixel(x, y, Color.FromArgb(0, c.G, 0));
}
}
// - Don't forget to save, until now we're only messing with the loaded memory of the bitmap.
red.Save("Red.bmp");
blue.Save("Blue.bmp");
green.Save("Green.bmp");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.