예제 #1
0
  private void newImage(Buffer buffer) {
    Object data = buffer.getData();
    if (!(data instanceof int[])) return;
    RGBFormat format = (RGBFormat) buffer.getFormat();

    DirectColorModel dcm =
        new DirectColorModel(
            format.getBitsPerPixel(),
            format.getRedMask(),
            format.getGreenMask(),
            format.getBlueMask());

    sourceImage =
        new MemoryImageSource(
            format.getLineStride(),
            format.getSize().height,
            dcm,
            (int[]) data,
            0,
            format.getLineStride());
    sourceImage.setAnimated(true);
    sourceImage.setFullBufferUpdates(true);
    if (component != null) {
      destImage = component.createImage(sourceImage);
      component.prepareImage(destImage, component);
    }
  }
예제 #2
0
 void createImage() {
   if (imageSource == null) {
     rgbCM = new DirectColorModel(32, 0xff0000, 0xff00, 0xff);
     imageSource = new MemoryImageSource(width, height, rgbCM, rgbPixels, 0, width);
     imageSource.setAnimated(true);
     imageSource.setFullBufferUpdates(true);
     awtImage = Toolkit.getDefaultToolkit().createImage(imageSource);
     newPixels = false;
   } else if (newPixels) {
     imageSource.newPixels(rgbPixels, rgbCM, 0, width);
     newPixels = false;
   } else imageSource.newPixels();
 }
  void createGraphics() {

    synchronized (
        imagSync) { // The synchronized modifier allows the user to lock objects that are shared
      // If you have more than one of your threads running at the same time that
      // access shared objects, it may cause your object to be in an inconsitent state
      // Making a method synchronized will lock the object. This means that no other thread can call
      // a synchronized method on that object.

      size =
          new Dimension(
              nChunks,
              nBins); // The dimension class 'encapsulates the width and height of a component in a
                      // single object
      // In this case i think the object imageSync
      int width = nChunks;
      int height = nBins; // nBins is the height maybe the no.of rows which get coloured in

      screenBuffer =
          new int[width * height]; // i think this creates an integer array called screenBuffer

      screenConverter =
          new MemoryImageSource(
              width,
              height, // The MemoryImageSource class--- This class is an implementation of the
                      // ImageProducer interface which uses an array to produce pixel values for an
                      // Image.
              screenBuffer,
              0,
              width); // The MemoryImageSource is also capable of managing a memory image which
                      // varies over time to allow animation or custom rendering.
      screenConverter.setAnimated(
          true); // Changes this memory image into a multi-frame animation or a single-frame static
                 // image depending on the animated parameter.This is a multframe animation
      screenConverter.setFullBufferUpdates(
          false); // Specifies whether this animated memory image should always be updated by
                  // sending the complete buffer of pixels whenever there is a change.
      offscreen =
          Toolkit.getDefaultToolkit()
              .createImage(
                  screenConverter); // Returns an image which gets pixel data from the specified
                                    // file. there other possible create image
      setPreferredSize(size);
    }
  }