Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4210706

Changes made directly to the WritableRaster of a BufferedImage do not show up

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.2.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • CPU:
      x86
    • OS:
      windows_95

      Description



      Name: gsC80088 Date: 02/10/99


      Dear Sir/Madam

      I tried to change the Raster data directly (Raster of an Image Buffer),but the program does not do the operation I
      implement in the code.Below is my code :

      import java.awt.*;
      import java.awt.event.*;
      import com.sun.image.codec.jpeg.*;
      import java.awt.image.BufferedImage;
      import java.awt.image.DataBuffer;
      import java.awt.geom.GeneralPath;
      import java.awt.color.ColorSpace;
      import java.io.*;
      import java.awt.image.Raster;
      import java.awt.image.WritableRaster;
      import java.lang.*;


      public class HW51a extends Canvas {

          private Image img;

          public HW51a() {
              setBackground(Color.white);
          }


          public void paint(Graphics g) {
              Graphics2D g2 = (Graphics2D) g;


      BufferedImage bi = new BufferedImage(256, 256,BufferedImage.TYPE_BYTE_GRAY);

      WritableRaster r = bi.getRaster();
      System.out.println(r.getHeight());
      System.out.println((r.getDataBuffer()).getDataTypeSize(0));
      System.out.println(r.getBounds());
      System.out.println(r.getNumBands());
      System.out.println(r.getNumDataElements());

      byte[] f = new byte[100];
      Integer x = new Integer(1);
      byte m = x.byteValue();
      for(int j = 0;j < 100 ; j++)
      f[j] = m;

      r.setDataElements(0,0,9,9,(Object)f);
      bi.setData((Raster)r);

      Graphics2D big = bi.createGraphics();

      // .. use rendering hints from J2DCanvas ..
              big.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                  RenderingHints.VALUE_ANTIALIAS_ON);
              big.setRenderingHint(RenderingHints.KEY_RENDERING,
                                  RenderingHints.VALUE_RENDER_QUALITY);

      big.setBackground(Color.white);
      big.clearRect(0, 0, 256, 256);

      big.setColor(Color.black);

      big.fillRect(64,120,128,16);


      big.drawImage(bi, 0, 0, this);
       

          }


          public static void main(String s[]) {
      WindowListener l = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {System.exit(0);}
      };
      Frame f = new Frame("Java2D Demo");
      f.setResizable(false);
      f.setLayout(null);
      HW51a hw = new HW51a();
      hw.setSize(new Dimension(256,256));
      f.add(hw);
      f.addWindowListener(l);
      f.pack();
      f.setSize(new Dimension(256,256));
      f.show();
          }
      }

      If you compile it you will see that it doesnt paint the rectangle that I directly write into the raster of the BufferedImage.Waiting for an answer about that..

      Sincerely
      Cenk Demiroglu
      (Review ID: 47416)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            flar Jim Graham
            Reporter:
            gstone Greg Stone
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: