title: How to apply the grayscale effect to the Bitmap image?
body: <p>I want to convert the bitmap image into the Grayscale.For that i am using the NDK to boost the app performance.I have apply the other effect successfully.</p>
  
  <p><strong>Problem ::</strong></p>
  
  <p>The code which i am using to apply the grayscale is taken from the C##.So,i want to convert it into the NDK.I am unable to do that part ..</p>
  
  <p>For reference, i am putting the code of how i have applied the cyan effect to image.</p>
  
  <p>Below pasted code is working fine.</p>
  
  <pre><code>void applyCyano(Bitmap* bitmap) {
      //Cache to local variables
      unsigned char* red = (*bitmap).red;
      unsigned char* green = (*bitmap).green;
      unsigned char* blue = (*bitmap).blue;
  
      unsigned int length = (*bitmap).width * (*bitmap).height;
      register unsigned int i;
      register unsigned char grey, r, g, b;
      for (i = length; i--;) {
          grey = ((red[i] * 0.222f) + (green[i] * 0.222f) + (blue[i] * 0.222f));
          r = componentCeiling(61.0f + grey);
          g = componentCeiling(87.0f + grey);
          b = componentCeiling(136.0f + grey);
  
          grey = blackAndWhite(red[i], green[i], blue[i]);
          red[i] = overlayPixelComponents(grey, r, 0.9f);
          green[i] = overlayPixelComponents(grey, g, 0.9f);
          blue[i] = overlayPixelComponents(grey, b, 0.9f);
      }
  }
  </code></pre>
  
  <p><strong>The code to appply Grayscale effect(taken from C## example over the net) ::</strong></p>
  
  <pre><code>void applyGrayscaleNatively(Bitmap* original)
  {
      //create an empty bitmap the same size as original
      Bitmap newBitmap = new Bitmap(original.Width, original.Height);
  
      //lock the original bitmap in memory
      BitmapData originalData = original.LockBits(
              new Rectangle(0, 0, original.Width, original.Height),
              ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  
      //lock the new bitmap in memory
      BitmapData newData = newBitmap.LockBits(
              new Rectangle(0, 0, original.Width, original.Height),
              ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
  
      //set the number of bytes per pixel
      int pixelSize = 3;
  
      for (int y = 0; y &lt; original.Height; y++)
      {
          //get the data from the original image
          byte* oRow = (byte*)originalData.Scan0 + (y * originalData.Stride);
  
          //get the data from the new image
          byte* nRow = (byte*)newData.Scan0 + (y * newData.Stride);
  
          for (int x = 0; x &lt; original.Width; x++)
          {
              //create the grayscale version
              byte grayScale =
                      (byte)((oRow[x * pixelSize] * .11) + //B
                              (oRow[x * pixelSize + 1] * .59) +  //G
                              (oRow[x * pixelSize + 2] * .3)); //R
  
              //set the new image's pixel to the grayscale version
              nRow[x * pixelSize] = grayScale; //B
              nRow[x * pixelSize + 1] = grayScale; //G
              nRow[x * pixelSize + 2] = grayScale; //R
          }
      }
  
      //unlock the bitmaps
      newBitmap.UnlockBits(newData);
      original.UnlockBits(originalData);
  }
  </code></pre>
  
  <p><strong>What i want to do ::</strong></p>
  
  <p>I have taken this project from the <a href="https://github.com/lightbox/PhotoProcessing" rel="nofollow">here</a> which have set the different effect to the image but not the grayscale.so how to apply the grayscale to the code so that all the other funcationality of the project won't stop.</p>
  
  <p>Let me know if you need anything from me .</p>
  
  <p>Many Thanks  in Advance..</p>
  
  <p>Please help me to resovle this issue as just because of this am not able to go further in my project.</p>