title: Why are my jpeg QR codes from ZXing not black and white?
body: <p>I'm using ZXing code to create QR bar codes. I got the example code from here working: <a href="http://www.vineetmanohar.com/2010/09/java-barcode-api/" rel="nofollow">http://www.vineetmanohar.com/2010/09/java-barcode-api/</a> and the PNG image looks good, black and white as expected. </p>
  
  <p>In the example codes comments it mentions I could use tiff or jpeg format so I changed the imgeFormat variable to jpeg. A correct looking QR code image is created but instead of being black and white the "white" part is a peach color and the "black" part is a blue color. </p>
  
  <p>I cut and past the ZXing MatrixToImageWriter code into my code and set the colors instead of using the int BLACK = 0xFF000000; and int WHITE = 0xFFFFFFFF; I found that by replacing the BLACK variable with with 0x00000000 I got black on my image, but I have been unable to find a value for the WHITE variable that give me a white. </p>
  
  <p><strike>Attached is the odd colored QR barcode.</strike> Oops, I'm too new of a user to attach an image. Hopefully this link to imgur.com works: <a href="http://imgur.com/QnNXO" rel="nofollow">http://imgur.com/QnNXO</a></p>
  
  <p>Here is the Java code:</p>
  
  <pre><code>package zxing_qr;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import com.google.zxing.BarcodeFormat;
  import com.google.zxing.WriterException;
  import com.google.zxing.client.j2se.MatrixToImageWriter;
  import com.google.zxing.common.BitMatrix;
  import com.google.zxing.qrcode.QRCodeWriter;
  
  // by passing MatrixToImageWriter call
  import javax.imageio.ImageIO;
  import java.awt.image.BufferedImage;
  import java.awt.Graphics2D;
  
  
  public class Main {
  
  
  public static void main(String[] args) {
      //String text = "98376373783"; // this is the text that we want to encode
      String text = "blahblahblah"; // this is the text that we want to encode
  
      int width = 400;
      int height = 300; // change the height and width as per your requirement
  
      // (ImageIO.getWriterFormatNames() returns a list of supported formats)
      String imageFormat = "jpg"; // could be "gif", "tiff", "jpeg"
  
      try {
          BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE,     width, height);
          MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, new FileOutputStream(new File("qrcode_97802017507991.jpg")));             
      } catch (WriterException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  } // end main function
  } // end main class
  </code></pre>