2016-10-07 5 views
0

Ich möchte ein Programm Zoom und Zoom Out Funktion haben. (2x, 4x, 8x) Aber ich kann nicht eine verfügbare Zoom-Funktion verwenden. Ich muss ein neues schreiben one.Ich habe das Importieren von Bitmap-Bild.Und ich kann rgb Farbe für jedes Pixel.Ich erstellte Matrizen colorR, colorG und colorB für r, g und b Farben.Nachdem dachte ich, ich kann das 2x gezoomte Bild mit SolidBrush auf einem erstellen panel.I wird 2x Bild wie folgt zeichnen:C# Vergrößern und Verkleinern eines Bildes

Originalbild (beispielsweise 3x3 Bildpunkte) (p = Pixelfarbe und "_" für Raum)

p1_p2_p3

p4_p5_p6

p7_p8_p9

2x gezoomte Bild (6x6 Pixel wegen der ursprünglichen Bildgröße) (p = Pixelfarbe des ursprünglichen Bildes und "_" für Raum)

p1_p1_p2_p2_p3_p3

p1_p1_p2_p2_p3_p3

p4_p4_p5_p5_p6_p6

p4_p4_p5_p5_p6_p6

p7_p7_p8_p8_p9_p9

p7_p7_p8_p8_p9_p9

Ich schrieb eine Schleife, aber es hat nicht funktioniert, weil es complety wrong.So ist, wie kann ich für Schleifen schreiben ?

private void button4_Click(object sender, EventArgs e) { 
     listBox1.Items.Clear();//insignificant 
     listBox2.Items.Clear();//insignificant 
     listBox3.Items.Clear();//insignificant 

     using (OpenFileDialog dlg = new OpenFileDialog()) { 
      dlg.Title = "Open Image"; 
      dlg.Filter = "*.bmp|*.bmp|*.*|*.*"; 

      if (dlg.ShowDialog() == DialogResult.OK) { 
       pictureBox1.Image = new Bitmap(dlg.FileName); 
      } 
     } 
    } 

    private void button1_Click(object sender, EventArgs e) { 
     Graphics my2xImage = panel1.CreateGraphics(); 

     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 
     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 

     int[,] colorR = new int[bmpHeight, bmpWidth]; 
     int[,] colorG = new int[bmpHeight, bmpWidth]; 
     int[,] colorB = new int[bmpHeight, bmpWidth]; 



     for (int y = 0; y < bmpHeight; y++) { 
      for (int x = 0; x < bmpWidth; x++) { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       colorR[x, y] = pixelColor.R; 
       colorG[x, y] = pixelColor.G; 
       colorB[x, y] = pixelColor.B; 

       listBox1.Items.Add("(" + (x + 1) + "," + (y + 1) + ")" + " " + colorR[x, y]);//insignificant 
       listBox2.Items.Add("(" + (x + 1) + "," + (y + 1) + ")" + " " + colorG[x, y]);//insignificant 
       listBox3.Items.Add("(" + (x + 1) + "," + (y + 1) + ")" + " " + colorB[x, y]);//insignificant 

      } 

     } 



     //for (int y = 0; y < (bmpHeight * 2); y++) 
     //{ 
     // for (int x = 0; x < (bmpWidth * 2); x++) 
     // { 
     //  Color mySpecialColor = Color.FromArgb(colorR[x,y], colorG[x,y], colorB[x,y]); 
     //  SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
     //  my2xImage.FillRectangle(pixelBrush, x, y, 1, 1); 
     // } 
     //} 


    } 

    private void button5_Click(object sender, EventArgs e) { 

    } 

    private void button2_Click(object sender, EventArgs e) { 

    } 

Antwort

0

Das ist verrückt, aber wenn man wirklich muss dies tut, wie es dann so etwas wie dies versucht:

  int dx = x*2; 
      int dy = y*2; 

      colorR[dx ,dy ] = pixelColor.R; 
      colorR[dx+1,dy ] = pixelColor.R; 
      colorR[dx ,dy+1] = pixelColor.R; 
      colorR[dx+1,dy+1] = pixelColor.R; 

      colorG[dx ,dy ] = pixelColor.G; 
      colorG[dx+1,dy ] = pixelColor.G; 
      colorG[dx ,dy+1] = pixelColor.G; 
      colorG[dx+1,dy+1] = pixelColor.G; 

      colorB[dx ,dy ] = pixelColor.B; 
      colorB[dx+1,dy ] = pixelColor.B; 
      colorB[dx ,dy+1] = pixelColor.B; 
      colorB[dx+1,dy+1] = pixelColor.B; 
+0

Ich habe es versucht.Aber es hat nicht funktioniert.Ich denke, es überschreibt auf matris.So die gezeichnete Bildkopie des ersten Bildes und die restlichen Pixel sind schwarz.Just wie folgt: [link] (http://fs5.directupload.ne t/images/161008/jzhf6sgi.jpg) –

+0

Wenn das verknüpfte Bild das ist, was du gemacht hast, dann hast du es nicht versucht. Du hast einen seltsamen Weg aus deiner eigenen Erfindung versucht, aber nicht auf meine Art. Mein Weg ist in meiner Antwort aufgeführt. Und es wird funktionieren. Wenn du es versuchst. –

+0

Es schien mir das gleiche.Ich suche 10 Minuten, um zu verstehen, wie Sie Ihren Weg schreiben, aber ich kann es nicht tun.Wie bekomme ich jedes Pixel des Bildes und wie jedes Pixel von 2x Zoom im Bild einzustellen? Kannst du bitte in Code schreiben? :( –

0

Sie sollten die DrawImage Methode der Graphics Klasse.

Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 

Graphics g = Graphics.FromImage(bmpFirst); 

// Draw image to screen. 
g.DrawImage(newImage, destRect, x, y, width, height, units); 

Schauen Sie hier: https://msdn.microsoft.com/en-us/library/ms142045(v=vs.110).aspx

hier Schauen Sie auch: https://msdn.microsoft.com/en-us/library/k0fsyd4e(v=vs.110).aspx

Sie auch die Interpolation Modus einstellen: https://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.interpolationmode(v=vs.110).aspx

Sie sind für die NearestNeighbor Interpolationsmodus suchen.

+0

Vielen Dank für links.But Ich weiß nicht, warum ich e.Graphics.DrawImage nicht schreiben kann (bla, bla, bla) part.Ich kann e nicht schreiben und Punkt setzen, sondern zeigt nur diese Befehle: "Equals, GetHashCode, GetType, ToString" Wissen Sie, warum "Graphics" -Befehl nicht erschien? –

+0

Mein schlechtes. Es sollte 'g.DrawImage sein() ' –

0

Er ist die Lösung.

private void button4_Click(object sender, EventArgs e  ) 
    { 
     listBox1.Items.Clear(); 
     listBox2.Items.Clear(); 
     listBox3.Items.Clear(); 

     using (OpenFileDialog dlg = new OpenFileDialog()) 
     { 
      dlg.Title = "Open Image"; 
      dlg.Filter = "*.bmp|*.bmp|*.*|*.*"; 

      if (dlg.ShowDialog() == DialogResult.OK) 
      { 
       pictureBox1.Image = new Bitmap(dlg.FileName); 
      } 
     } 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 


     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 
     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel1.CreateGraphics(); 




     int[,] colorR = new int[bmpHeight*2 , bmpWidth*2]; 
     int[,] colorG = new int[bmpHeight*2 , bmpWidth*2]; 
     int[,] colorB = new int[bmpHeight*2 , bmpWidth*2]; 



     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       int dx = x * 2; 
       int dy = y * 2; 

       colorR[dx, dy] = pixelColor.R; 
       colorR[dx + 1, dy] = pixelColor.R; 
       colorR[dx, dy + 1] = pixelColor.R; 
       colorR[dx + 1, dy + 1] = pixelColor.R; 

       colorG[dx, dy] = pixelColor.G; 
       colorG[dx + 1, dy] = pixelColor.G; 
       colorG[dx, dy + 1] = pixelColor.G; 
       colorG[dx + 1, dy + 1] = pixelColor.G; 

       colorB[dx, dy] = pixelColor.B; 
       colorB[dx + 1, dy] = pixelColor.B; 
       colorB[dx, dy + 1] = pixelColor.B; 
       colorB[dx + 1, dy + 1] = pixelColor.B; 




      } 

     } 



     for (int y = 0; y < (bmpHeight*2); y++) 
     { 
      for (int x = 0; x < (bmpWidth*2); x++) 
      { 
       Color mySpecialColor = Color.FromArgb(colorR[x, y], colorG[x, y], colorB[x, y]); 
       SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
       g.FillRectangle(pixelBrush, x, y, 1, 1); 
      } 
     } 
+0

Gerax, auf stackoverflow, Kopieren der Antworten anderer Leute ist in der Regel verpönt. –

+0

Warum? Ich habe nichts falsch gemacht. Ich schreibe den letzten Code, um jemanden Hilfe über Google zu bekommen. Und ich kann diesen Code wegen @Mike Nakis schreiben. Sie können unsere Gespräche lesen. Abgesehen davon ist der Lösungscode richtig? Wie ist das möglich anders zu schreiben? Ich habe mit for loops geschrieben, aber die selbe Logik. Selbst ich werde die überarbeitete Lösung hier schreiben, damit jeder sie sehen kann. Aber Sie haben Recht, ich muss "Mike Nakis" auf meine Antwort schreiben, aber ich habe sowieso zu viel geredet .Einen schönen Tag noch :) –

0

Sie können für Schleifen für Farbe verwenden [dx, dy] parts.Here es für 8-fach Zoom ist.

 int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 

     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel3.CreateGraphics(); 

     int[,] colorR = new int[bmpHeight * 8, bmpWidth * 8]; 
     int[,] colorG = new int[bmpHeight * 8, bmpWidth * 8]; 
     int[,] colorB = new int[bmpHeight * 8, bmpWidth * 8]; 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       int dx = x * 8; 
       int dy = y * 8; 

       for (int i = 0; i < 8; i++) 
       { 
        for (int j = 0; j < 8; j++) 
        { 
         colorR[dx + j, dy + i] = pixelColor.R; 
         colorG[dx + j, dy + i] = pixelColor.G; 
         colorB[dx + j, dy + i] = pixelColor.B; 
        } 
       } 

      } 
0

Voll Code (Sie können auch herunterladen Projekt: Link

private void button4_Click(object sender, EventArgs e  ) 
    { 
     tabControl1.SelectedTab = tabPage1; 

     using (OpenFileDialog dlg = new OpenFileDialog()) 
     { 
      dlg.Title = "Open Image"; 
      dlg.Filter = "*.bmp|*.bmp|*.jpg|*.jpg|*.*|*.*"; 

      if (dlg.ShowDialog() == DialogResult.OK) 
      { 
       pictureBox1.Image = new Bitmap(dlg.FileName); 
      } 
     } 

     if (pictureBox1.Image == null) 
     { 
      MessageBox.Show("Please choose a image file."); 
     } 
     else 
     { 
      int bmpHeight = pictureBox1.Image.Height; 
      int bmpWidth = pictureBox1.Image.Width; 

      if (bmpHeight > 100 || bmpWidth > 100) 
      { 
       MessageBox.Show("Image size can't be bigger than 100x100 pixels"); 
       button1.Enabled = false; 
       button2.Enabled = false; 
       button3.Enabled = false; 
       button5.Enabled = false; 
       button6.Enabled = false; 
       button7.Enabled = false; 
       button10.Enabled = false; 
      } 
      else 
      { 
       button1.Enabled = true; 
       button2.Enabled = true; 
       button3.Enabled = true; 
       button5.Enabled = false; 
       button6.Enabled = false; 
       button7.Enabled = false; 
       button10.Enabled = false; 
      } 
     } 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 
     tabControl1.SelectedTab = tabPage2; 

     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 

     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel1.CreateGraphics(); 

     int[,] colorR = new int[bmpWidth * 2 , bmpHeight *2]; 
     int[,] colorG = new int[bmpWidth * 2 , bmpHeight *2]; 
     int[,] colorB = new int[bmpWidth * 2 , bmpHeight *2]; 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       int dx = x * 2; 
       int dy = y * 2; 

       for (int i = 0; i < 2; i++) 
       { 
        for (int j = 0; j < 2; j++) 
        { 
         colorR[dx + i, dy + j] = pixelColor.R; 
         colorG[dx + i, dy + j] = pixelColor.G; 
         colorB[dx + i, dy + j] = pixelColor.B; 
        } 
       } 
      } 

     } 

     for (int y = 0; y < (bmpHeight*2); y++) 
     { 
      for (int x = 0; x < (bmpWidth*2); x++) 
      { 
       Color mySpecialColor = Color.FromArgb(colorR[x, y], colorG[x, y], colorB[x, y]); 
       SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
       g.FillRectangle(pixelBrush, x, y, 1, 1); 
      } 
     } 
    } 

    private void button5_Click(object sender, EventArgs e) 
    { 

    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 
     tabControl1.SelectedTab = tabPage3; 

     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 

     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel2.CreateGraphics(); 

     int[,] colorR = new int[bmpWidth * 4, bmpHeight * 4]; 
     int[,] colorG = new int[bmpWidth * 4, bmpHeight * 4]; 
     int[,] colorB = new int[bmpWidth * 4, bmpHeight * 4]; 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       int dx = x * 4; 
       int dy = y * 4; 

       for (int i = 0; i < 4; i++) 
       { 
        for (int j = 0; j < 4; j++) 
        { 
         colorR[dx + i, dy + j] = pixelColor.R; 
         colorG[dx + i, dy + j] = pixelColor.G; 
         colorB[dx + i, dy + j] = pixelColor.B; 
        } 
       } 
      } 

     } 

     for (int y = 0; y < (bmpHeight * 4); y++) 
     { 
      for (int x = 0; x < (bmpWidth * 4); x++) 
      { 
       Color mySpecialColor = Color.FromArgb(colorR[x, y], colorG[x, y], colorB[x, y]); 
       SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
       g.FillRectangle(pixelBrush, x, y, 1, 1); 
      } 
     } 

    } 


    private void panel1_Paint(object sender, PaintEventArgs e) 
    { 


    } 

    private void pictureBox1_Click(object sender, EventArgs e) 
    { 

    } 

    private void button5_Click_1(object sender, EventArgs e) 
    { 


    } 

    private void tabPage2_Click(object sender, EventArgs e) 
    { 

    } 

    private void button3_Click(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 
     tabControl1.SelectedTab = tabPage4; 

     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 

     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel3.CreateGraphics(); 

     int[,] colorR = new int[bmpWidth * 8, bmpHeight * 8]; 
     int[,] colorG = new int[bmpWidth * 8, bmpHeight * 8]; 
     int[,] colorB = new int[bmpWidth * 8, bmpHeight * 8]; 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       int dx = x * 8; 
       int dy = y * 8; 

       for (int i = 0; i < 8; i++) 
       { 
        for (int j = 0; j < 8; j++) 
        { 
         colorR[dx + i, dy + j] = pixelColor.R; 
         colorG[dx + i, dy + j] = pixelColor.G; 
         colorB[dx + i, dy + j] = pixelColor.B; 
        } 
       } 

      } 

     } 

     for (int y = 0; y < (bmpHeight * 8); y++) 
     { 
      for (int x = 0; x < (bmpWidth * 8); x++) 
      { 
       Color mySpecialColor = Color.FromArgb(colorR[x, y], colorG[x, y], colorB[x, y]); 
       SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
       g.FillRectangle(pixelBrush, x, y, 1, 1); 
      } 
     } 
    } 

    private void button5_Click_2(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 
     tabControl1.SelectedTab = tabPage5; 

     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 

     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel4.CreateGraphics(); 

     int[,] colorR = new int[bmpWidth, bmpHeight]; 
     int[,] colorG = new int[bmpWidth, bmpHeight]; 
     int[,] colorB = new int[bmpWidth, bmpHeight]; 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       colorR[x, y] = pixelColor.R; 

       colorG[x, y] = pixelColor.G; 

       colorB[x, y] = pixelColor.B; 

      } 
     } 

     int[,] colorSR = new int[bmpWidth /2, bmpHeight /2]; 
     int[,] colorSG = new int[bmpWidth /2, bmpHeight /2]; 
     int[,] colorSB = new int[bmpWidth /2, bmpHeight /2]; 

     for (int i = 0; i < bmpWidth/2; i++) 
     { 
      for (int j = 0; j < bmpHeight /2; j++) 
      { 
       colorSR[i, j] = (colorR[2 * i, 2 * j] + colorR[2 * i, 2 * j + 1] + colorR[2 * i + 1, 2 * j] + colorR[2 * i + 1, 2 * j + 1])/4; 
       colorSG[i, j] = (colorG[2 * i, 2 * j] + colorG[2 * i, 2 * j + 1] + colorG[2 * i + 1, 2 * j] + colorG[2 * i + 1, 2 * j + 1])/4; 
       colorSB[i, j] = (colorB[2 * i, 2 * j] + colorB[2 * i, 2 * j + 1] + colorB[2 * i + 1, 2 * j] + colorB[2 * i + 1, 2 * j + 1])/4; 
      } 
     } 

     for (int y = 0; y < (bmpHeight/2); y++) 
     { 
      for (int x = 0; x < (bmpWidth/2); x++) 
      { 
       Color mySpecialColor = Color.FromArgb(colorSR[x, y], colorSG[x, y], colorSB[x, y]); 
       SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
       g.FillRectangle(pixelBrush, x, y, 1, 1); 
      } 
     } 
    } 

    private void groupBox1_Enter(object sender, EventArgs e) 
    { 

    } 

    private void button6_Click(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 
     tabControl1.SelectedTab = tabPage6; 

     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 

     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel5.CreateGraphics(); 

     int[,] colorR = new int[bmpWidth, bmpHeight]; 
     int[,] colorG = new int[bmpWidth, bmpHeight]; 
     int[,] colorB = new int[bmpWidth, bmpHeight]; 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       colorR[x, y] = pixelColor.R; 
       colorG[x, y] = pixelColor.G; 
       colorB[x, y] = pixelColor.B; 

      } 
     } 

     int[,] colorSR = new int[bmpWidth/4, bmpHeight/4]; 
     int[,] colorSG = new int[bmpWidth/4, bmpHeight/4]; 
     int[,] colorSB = new int[bmpWidth/4, bmpHeight/4]; 

     for (int i = 0; i < bmpWidth/4; i++) 
     { 
      for (int j = 0; j < bmpHeight/4; j++) 
      { 
       colorSR[i, j] = (colorR[4 * i, 4 * j] + colorR[4 * i, 4 * j + 1] + colorR[4 * i + 1, 4 * j] + colorR[4 * i + 1, 4 * j + 1])/4; 
       colorSG[i, j] = (colorG[4 * i, 4 * j] + colorG[4 * i, 4 * j + 1] + colorG[4 * i + 1, 4 * j] + colorG[4 * i + 1, 4 * j + 1])/4; 
       colorSB[i, j] = (colorB[4 * i, 4 * j] + colorB[4 * i, 4 * j + 1] + colorB[4 * i + 1, 4 * j] + colorB[4 * i + 1, 4 * j + 1])/4; 
      } 
     } 

     for (int y = 0; y < (bmpHeight/4); y++) 
     { 
      for (int x = 0; x < (bmpWidth/4); x++) 
      { 
       Color mySpecialColor = Color.FromArgb(colorSR[x, y], colorSG[x, y], colorSB[x, y]); 
       SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
       g.FillRectangle(pixelBrush, x, y, 1, 1); 
      } 
     } 
    } 

    private void button7_Click(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 
     tabControl1.SelectedTab = tabPage7; 

     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 

     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel6.CreateGraphics(); 

     int[,] colorR = new int[bmpWidth, bmpHeight]; 
     int[,] colorG = new int[bmpWidth, bmpHeight]; 
     int[,] colorB = new int[bmpWidth, bmpHeight]; 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       colorR[x, y] = pixelColor.R; 
       colorG[x, y] = pixelColor.G; 
       colorB[x, y] = pixelColor.B; 

      } 
     } 

     int[,] colorSR = new int[bmpWidth/8, bmpHeight/8]; 
     int[,] colorSG = new int[bmpWidth/8, bmpHeight/8]; 
     int[,] colorSB = new int[bmpWidth/8, bmpHeight/8]; 

     for (int i = 0; i < bmpWidth/8; i++) 
     { 
      for (int j = 0; j < bmpHeight/8; j++) 
      { 
       colorSR[i, j] = (colorR[8 * i, 8 * j] + colorR[8 * i, 8 * j + 1] + colorR[8 * i + 1, 8 * j] + colorR[8 * i + 1, 8 * j + 1])/4; 
       colorSG[i, j] = (colorG[8 * i, 8 * j] + colorG[8 * i, 8 * j + 1] + colorG[8 * i + 1, 8 * j] + colorG[8 * i + 1, 8 * j + 1])/4; 
       colorSB[i, j] = (colorB[8 * i, 8 * j] + colorB[8 * i, 8 * j + 1] + colorB[8 * i + 1, 8 * j] + colorB[8 * i + 1, 8 * j + 1])/4; 
      } 
     } 

     for (int y = 0; y < (bmpHeight/8); y++) 
     { 
      for (int x = 0; x < (bmpWidth/8); x++) 
      { 
       Color mySpecialColor = Color.FromArgb(colorSR[x, y], colorSG[x, y], colorSB[x, y]); 
       SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
       g.FillRectangle(pixelBrush, x, y, 1, 1); 
      } 
     } 
    } 

    private void button8_Click(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 

     using (OpenFileDialog dlg = new OpenFileDialog()) 
     { 
      dlg.Title = "Open Image"; 
      dlg.Filter = "*.bmp|*.bmp|*.jpg|*.jpg|*.*|*.*"; 

      if (dlg.ShowDialog() == DialogResult.OK) 
      { 
       pictureBox1.Image = new Bitmap(dlg.FileName); 
      } 
     } 

     if (pictureBox1.Image == null) 
     { 
      MessageBox.Show("Please choose a image file."); 
     } 
     else 
     { 

      int bmpHeight = pictureBox1.Image.Height; 
      int bmpWidth = pictureBox1.Image.Width; 

      if (bmpHeight > 800 || bmpWidth > 800) 
      { 
       MessageBox.Show("Image size can't be bigger than 800x800 pixels."); 
       button1.Enabled = false; 
       button2.Enabled = false; 
       button3.Enabled = false; 
       button5.Enabled = false; 
       button6.Enabled = false; 
       button7.Enabled = false; 
       button10.Enabled = false; 
      } 
      else 
      { 
       button1.Enabled = false; 
       button2.Enabled = false; 
       button3.Enabled = false; 
       button5.Enabled = true; 
       button6.Enabled = true; 
       button7.Enabled = true; 
       button10.Enabled = false; 
      } 
     } 
    } 

    private void groupBox2_Enter(object sender, EventArgs e) 
    { 

    } 

    private void button10_Click(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 
     tabControl1.SelectedTab = tabPage8; 

     int bmpHeight = pictureBox1.Image.Height; 
     int bmpWidth = pictureBox1.Image.Width; 

     Bitmap bmpFirst = (Bitmap)pictureBox1.Image.Clone(); 
     Graphics g = panel7.CreateGraphics(); 

     int[,] colorR = new int[bmpWidth, bmpHeight]; 
     int[,] colorG = new int[bmpWidth, bmpHeight]; 
     int[,] colorB = new int[bmpWidth, bmpHeight]; 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       Color pixelColor = bmpFirst.GetPixel(x, y); 

       colorR[x, y] = pixelColor.R; 
       colorG[x, y] = pixelColor.G; 
       colorB[x, y] = pixelColor.B; 

      } 
     } 

     for (int y = 0; y < bmpHeight; y++) 
     { 
      for (int x = 0; x < bmpWidth; x++) 
      { 
       int dx = bmpWidth - 1; 
       int dy = bmpHeight - 1; 
       Color mySpecialColor = Color.FromArgb(colorR[dx - x, dy - y], colorG[dx - x, dy - y], colorB[dx - x, dy - y]); 
       SolidBrush pixelBrush = new SolidBrush(mySpecialColor); 
       g.FillRectangle(pixelBrush, x, y, 1, 1); 
      } 
     } 
    } 

    private void button9_Click(object sender, EventArgs e) 
    { 
     tabControl1.SelectedTab = tabPage1; 

     using (OpenFileDialog dlg = new OpenFileDialog()) 
     { 
      dlg.Title = "Open Image"; 
      dlg.Filter = "*.bmp|*.bmp|*.jpg|*.jpg|*.*|*.*"; 

      if (dlg.ShowDialog() == DialogResult.OK) 
      { 
       pictureBox1.Image = new Bitmap(dlg.FileName); 
      } 
     } 

     if (pictureBox1.Image == null) 
     { 
      MessageBox.Show("Please choose a image file."); 
     } 
     else 
     { 
      int bmpHeight = pictureBox1.Image.Height; 
      int bmpWidth = pictureBox1.Image.Width; 

      if (bmpHeight > 800 || bmpWidth > 800) 
      { 
       MessageBox.Show("Image size can't be bigger than 800x800 pixels"); 
       button1.Enabled = false; 
       button2.Enabled = false; 
       button3.Enabled = false; 
       button5.Enabled = false; 
       button6.Enabled = false; 
       button7.Enabled = false; 
       button10.Enabled = false; 
      } 
      else 
      { 
       button1.Enabled = false; 
       button2.Enabled = false; 
       button3.Enabled = false; 
       button5.Enabled = false; 
       button6.Enabled = false; 
       button7.Enabled = false; 
       button10.Enabled = true; 
      } 
     } 
    } 
} 
Verwandte Themen