2017-10-12 3 views
0

J'ai besoin de convertir l'image noire en niveaux de gris image.my convertir l'image couleur en niveaux de gris image.but ne convertira pas image noire en échelle de gris image.Eva essayer un échantillon de stackoverflow pour conversion en niveaux de gris .that également ne fonctionne pas pour l'échelle de noir à l'échelle de gris conversion d'image. ce lien est https://stackoverflow.com/a/2265990/8569792Noir image convertir en échelle de gris Image

public void GreyScaleConversion() 
{   
    //read image 
    Bitmap bmp = global::Ribbon.Properties.Resources.Device; 

    //load original image in picturebox1 
    pictureBox1.Image = global::Ribbon.Properties.Resources.Device; 

    //get image dimension 
    int width = bmp.Width; 
    int height = bmp.Height; 

    //color of pixel 
    Color p; 

    //grayscale 
    for (int y = 0; y < height; y++) 
    { 
     for (int x = 0; x < width; x++) 
     { 
      //get pixel value 
      p = bmp.GetPixel(x, y); 

      //extract pixel component ARGB 
      int a = p.A; 
      int r = p.R; 
      int g = p.G; 
      int b = p.B; 

      //find average 
      int avg = (r + g + b)/3; 

      //set new pixel value 
      bmp.SetPixel(x, y, Color.FromArgb(a, avg, avg, avg)); 
     } 
    } 

    //load grayscale image in picturebox2 
    pictureBox2.Image = bmp; 
} 

Répondre

0
public void GreyScaleConversion() 
    { 
     //read image 
     Bitmap bmp = global::Ribbon.Properties.Resources.Device; 

     //load original image in picturebox1 
     pictureBox1.Image = global::Ribbon.Properties.Resources.Device; 

     //get image dimension 
     int width = bmp.Width; 
     int height = bmp.Height; 

     //color of pixel 
     Color p; 

     //grayscale 
     for (int y = 0; y < height; y++) 
     { 
      for (int x = 0; x < width; x++) 
      { 
       //get pixel value 
       p = bmp.GetPixel(x, y); 

       //extract pixel component A 
       int a = p.A; 

       //set new pixel value 
       bmp.SetPixel(x, y, Color.FromArgb(a, 155, 155, 155)); 
      } 
     } 

     //load grayscale image in picturebox2 
     pictureBox2.Image = bmp; 
    }