Issue #4 resolved

failure as applet

Alessio Caiazza
repo owner created an issue

from macno

ubuntu 9.04, firefox 3.0.10 e java 1.5

{{{ Disabling captureEvent() for panel0 because of an error. java.lang.ClassCastException: [I at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:347) at processing.core.PImage.<init>(PImage.java:182) at it.lilik.capturemjpeg.CaptureMJPEG.run(CaptureMJPEG.java:317) }}}

Comments (4)

  1. Alessio Caiazza reporter

    PImage now manage BufferedImage in a different way, this causes exception to raise.

    Index: core/src/processing/core/PImage.java
    ===================================================================
    --- core/src/processing/core/PImage.java	(revisione 3705)
    +++ core/src/processing/core/PImage.java	(copia locale)
    
       /**
        * Construct a new PImage from a java.awt.Image. This constructor assumes
        * that you've done the work of making sure a MediaTracker has been used
        * to fully download the data and that the img is valid.
        */
       public PImage(java.awt.Image img) {
    -    width = img.getWidth(null);
    -    height = img.getHeight(null);
    +    if (img instanceof BufferedImage) {
    +      BufferedImage bi = (BufferedImage) img;
    +      width = bi.getWidth();
    +      height = bi.getHeight();
    +      pixels = new int[width * height];
    +      WritableRaster raster = bi.getRaster();
    +      raster.getDataElements(0, 0, width, height, pixels);
     
    -    pixels = new int[width*height];
    -    PixelGrabber pg =
    -      new PixelGrabber(img, 0, 0, width, height, pixels, 0, width);
    -    try {
    -      pg.grabPixels();
    -    } catch (InterruptedException e) { }
    +    } else {  // go the old school java 1.0 route
    +      width = img.getWidth(null);
    +      height = img.getHeight(null);
    +      pixels = new int[width * height];
    +      PixelGrabber pg =
    +        new PixelGrabber(img, 0, 0, width, height, pixels, 0, width);
    +      try {
    +        pg.grabPixels();
    +      } catch (InterruptedException e) { }
    +    }
     
         format = RGB;
    -    cache = null;
    +//    cache = null;
       }
    
  2. Log in to comment