title: BufferedImage into OpenCV Mat in Java
body: <p>I've read the article here that suggests what I'm doing should work: <a href="https://stackoverflow.com/questions/14958643/converting-bufferedimage-to-mat-in-opencv">Converting BufferedImage to Mat in opencv</a></p>
  
  <p>Can anyone tell me why my output is so dramatically different than what's in the top left 10x10 pixels on my desktop?</p>
  
  <p>edit:</p>
  
  <p>original 10x10 image (eclipse logo basically): <a href="http://tinypic.com/r/35l5clt/5" rel="nofollow noreferrer">http://tinypic.com/r/35l5clt/5</a> </p>
  
  <p>after loading into Mat: <a href="http://tinypic.com/r/af7w90/5" rel="nofollow noreferrer">http://tinypic.com/r/af7w90/5</a></p>
  
  <pre><code>public static void main(String[] args) throws InterruptedException,
          AWTException, IOException {
  
      byte[] bgrPixelData = ScreenToImage.GetCurrentScreenImage();
      Mat screenFrame = new Mat(10, 10, CvType.CV_8UC3);
      screenFrame.put(0, 0, bgrPixelData);
  
      // Create a blank output image, that we will draw onto.
      Mat outputFrame = new Mat(screenFrame.size(), CvType.CV_8UC3);
  
      // Save output and display the openCV Mat image onto the screen.
      ImageToScreen.DrawImageToScreen("c:\\temp\\wtf.png", outputFrame);
  }
  
  
  public class ScreenToImage {
  
  public static byte[] GetCurrentScreenImage() throws AWTException,
          IOException {
      Robot robot = new Robot();
      Dimension d = new Dimension();
      d.height = 10;
      d.width = 10;
  
      BufferedImage screenShot = robot.createScreenCapture(new Rectangle(d));
  
      BufferedImage bgrScreenshot = new BufferedImage(screenShot.getWidth(),
              screenShot.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
      boolean done = bgrScreenshot.getGraphics().drawImage(screenShot, 0, 0, null);
  
      return ((DataBufferByte) bgrScreenshot.getRaster().getDataBuffer())
              .getData();
  }
  }
  static {
      System.loadLibrary("opencv_java246");
  }
  
  public class ImageToScreen extends JFrame{
  
  private static final long serialVersionUID = 1L;
  
  public static void DrawImageToScreen(String imgStr, Mat m){
      Highgui.imwrite(imgStr, m);
      JFrame frame = new JFrame("Screen Capture");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setResizable(true);
      frame.setLocationRelativeTo(null);
  
      ImageIcon image = new ImageIcon(imgStr);
      frame.setSize(image.getIconWidth()+10,image.getIconHeight()+35);
      // Draw the Image data into the BufferedImage
      JLabel label1 = new JLabel(" ", image, JLabel.CENTER);
      frame.getContentPane().add(label1);
  
      frame.validate();
      frame.setVisible(true);
  }
  }
  </code></pre>