<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>How to convert a colour image to grayscale</Title>
      <Shortcut>Howtoconvertacolourimagetograyscale</Shortcut>
      <Description>How to convert a colour image to grayscale [C#]</Description>
      <Author>J.Marc Piulachs</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=f843c9d6-548c-4c94-abfc-c147625bd5b7</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[public Bitmap ConvertToGrayscale(Bitmap source)
{
  Bitmap bm = new Bitmap(source.Width,source.Height);
  for(int y=0;y<bm.Height;y++)
  {
    for(int x=0;x<bm.Width;x++)
    {
      Color c=source.GetPixel(x,y);
      int luma = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11);
      bm.SetPixel(x,y,Color.FromArgb(luma,luma,luma));
    }
  }
  return bm;
}
]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>