Пример #1
0
  public myImageFade() {
    myImage1 = Toolkit.getDefaultToolkit().getImage("d:/1.jpg");
    myImage2 = Toolkit.getDefaultToolkit().getImage("d:/ball.gif");

    myImage1_scaled = myImage1.getScaledInstance(500, 500, Image.SCALE_FAST);
    myImage2_scaled = myImage2.getScaledInstance(500, 500, Image.SCALE_FAST);
    repaint();

    try {
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(myImage1, 0);
      mt.addImage(myImage2, 0);
      mt.waitForAll();

      PixelGrabber grab1 =
          new PixelGrabber(myImage1, 0, 0, picWidth, picHeight, m_Img1Pix, 0, picWidth);
      PixelGrabber grab2 =
          new PixelGrabber(myImage2, 0, 0, picWidth, picHeight, m_Img2Pix, 0, picWidth);

      grab1.grabPixels();
      grab2.grabPixels();

      System.out.println(m_Img1Pix.length);

      System.out.println(m_Img1Pix[18500]);

      m_ImgSrc = new MemoryImageSource(picWidth, picHeight, m_Pix, 0, picWidth);
      m_ImgSrc.setAnimated(true);
      m_Img = createImage(m_ImgSrc);
    } catch (InterruptedException e) {
    }
  }
Пример #2
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);
    }
  }
Пример #3
0
  public void putRegion(
      int viewWidth,
      int viewHeight,
      int regWidth,
      int regHeight,
      int regOffX,
      int regOffY,
      int[] regBuffer) {
    if (image == null) {
      setPreferredSize(new Dimension(viewWidth, viewHeight));
      imageBuffer = new int[viewWidth * viewHeight];
      imageSource = new MemoryImageSource(viewWidth, viewHeight, imageBuffer, 0, viewWidth);
      imageSource.setAnimated(true);
      image = createImage(imageSource);
    }

    int destIndex = regOffX + regOffY * viewWidth;
    int srcIndex = 0;
    int extraRowGap = viewWidth - regWidth;
    for (int j = 0; j < regHeight; j++, destIndex += extraRowGap)
      for (int i = 0; i < regWidth; i++, srcIndex++, destIndex++)
        imageBuffer[destIndex] = regBuffer[srcIndex];
    imageSource.newPixels(regOffX, regOffY, regWidth, regHeight);
    repaint(regOffX, regOffY, regWidth, regHeight);
  }
Пример #4
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);
    }
  }
Пример #6
0
 public Image getSection(int x, int y, int width, int height) {
   if (width > imgWidth || height > imgHeight) {
     // create new image source and pixel array
     size = width * height;
     pixels = new int[size];
     imageSource = new MemoryImageSource(width, height, pixels, 0, width);
     imageSource.setAnimated(true);
     // imageSource.setFullBufferUpdates(true);
     image = Toolkit.getDefaultToolkit().createImage(imageSource);
   }
   if (width > imgWidth || height > imgHeight || x != oldX || y != oldY) {
     // recreate pixel array
     int skipWidth = 0;
     if (width < imgWidth && height <= imgHeight) {
       skipWidth = imgWidth - width;
     }
     int index = 0;
     for (int aY = 0; aY < height; aY++) {
       for (int aX = 0; aX < width; aX++) {
         if (index >= size) {
           System.out.println("oops...");
         }
         // pixels[index] = encodeColor(stats.getValueAt(x + aX, y +
         // aY));
         pixels[index] = mapColor(stats.getValueAt(x + aX, y + aY));
         index++;
       }
       index += skipWidth; // skip pixels to the right of clip area
     }
     oldX = x;
     oldY = y;
     imageSource.newPixels(0, 0, width, height);
     // imageSource.newPixels();
   }
   if (width > imgWidth || height > imgHeight) {
     imgWidth = width;
     imgHeight = height;
   }
   return image;
 }