title: Cannot convert current canvas data into image in java
body: <p>I have a simple application that allows the user to draw in the canvas control.</p>
  
  <p>Now, what I want is converting that canvas into an image. So here's my code.</p>
  
  <pre><code>public void paint(Graphics g)
  {
      //super.paint(g);
      Graphics2D draw = (Graphics2D) g;
      if(this.is_beginning || this.to_save)
      {
          draw.setColor(Color.white);
          draw.fillRect(0, 0, this.getWidth(), this.getHeight());
          this.is_beginning= false;
      }
      if(this.m_alzada)
      {
          draw.setColor(Color.red);
          draw.drawLine(uX, uY, x, y);
  
      }
  }
  </code></pre>
  
  <p>And this is my method for save the image.</p>
  
  <pre><code>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      int w = canvas1.getWidth();
      int h = canvas1.getHeight();
      int type = BufferedImage.TYPE_INT_BGR;
      BufferedImage image = new BufferedImage(w,h,type);
      Graphics2D g2 = image.createGraphics(); 
      canvas1.to_save = true;
      canvas1.paint(g2);
      try {
          ImageIO.write(image, "png", new File("C:/Users/Uriel/Desktop/ejemplo.png"));
      } catch (IOException ex) {
          Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
      }
  
  }
  </code></pre>
  
  <p>All these result in a blank image, I know how the paint method works, and I realize that is in there where my problem is. But how can I do to drew everything the user have already drew in the paint method?</p>
  
  <p>Excuse me for my bad english, I'm from Mexico. Thanks by the way.</p>
  
  <p>I would like to knoe if there is anyway to make something like when you work with the Canvas og HTML5 and you get a matrix with the RGB info of each pixel in the canvas. Is it possible to do that with the canvas component in JAVA?</p>