title: how to negate a bitmap in android?
body: <p>I want to display the negative of a dicom image , by using bitmap I did so </p>
  
  <pre><code>public static Bitmap getNegativeImage(Bitmap img) {
              int w1 = img.getWidth();
              int h1 = img.getHeight();
              // int value[][] = new int[w1][h1];
              Bitmap gray = Bitmap.createBitmap(
                      w1, h1, img.getConfig());
              int value, alpha, r, g, b;
              for (int i = 0; i &lt; w1; i++) {
                  for (int j = 0; j &lt; h1; j++) {
                      value = img.getPixel(i, j); // store value
  
                      alpha = getAlpha(value);
                      r = 255 - getRed(value);
                      g = 255 - getGreen(value);
                      b = 255 - getBlue(value);
  
                      value = createRGB(alpha, r, g, b);
                      gray.setPixel(i, j, value);
                  }
              }
              return gray;
          }
  
          public static int createRGB(int alpha, int r, int g, int b) {
              int rgb = (alpha &lt;&lt; 24) + (r &lt;&lt; 16) + (g &lt;&lt; 8) + b;
              return rgb;
          }
  
          public static int getAlpha(int rgb) {
              return (rgb &gt;&gt; 24) &amp; 0xFF;
          }
  
          public static int getRed(int rgb) {
              return (rgb &gt;&gt; 16) &amp; 0xFF;
          }
  
          public static int getGreen(int rgb) {
              return (rgb &gt;&gt; 8) &amp; 0xFF;
          }
  
          public static int getBlue(int rgb) {
              return rgb &amp; 0xFF;
          }
  </code></pre>
  
  <p>But the inverted(negative ) image gets black out, on clicking again the original image appears but the inverted image is not displayed.</p>
  
  <p>Regards
  Sathya U M</p>