⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageprobe.java

📁 用java写的jt-jpeg。jt表示java time package
💻 JAVA
字号:
package jpeg;
import jcp.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;

/**
 *  A probe for displaying image signals, represented as IntMatrix signals
 */
public class ImageProbe extends AsynchComponent
{
    //private ImageFrame myFrame;
    private ImageCanvas myCanvas;

    public ImageProbe() {
        setName("Image Probe");
        addPort(true,"in");
        myCanvas = new ImageCanvas();
        Frame f = new Frame();
        f.setTitle(name());
        f.setSize(100,100);
        f.add("Center", myCanvas);
        f.setVisible(true);
        f.addWindowListener(new MyWindowAdapter(f));
    }

    final class MyWindowAdapter extends java.awt.event.WindowAdapter {
        Frame f;
        public MyWindowAdapter(Frame f) {
            this.f = f;
        }
        public void windowClosing(WindowEvent e) {
            f.setVisible(false);
        }
    }

    public ImageProbe(ImageCanvas canvas) {
        setName("Image Probe");
        addPort(true,"in");
        myCanvas = canvas;
        //myCanvas.addWindowListener(new ImageFrameAdapter());
        myCanvas.setSize(100,100);
    }

    public void go(Port port) {

        Object s = port.signal();

        if (s instanceof IntMatrix) {
            int[][] matrix = ((IntMatrix)s).get_matrix();
            //myFrame.showImage(convertToArray(matrix));
            myCanvas.showImage(convertToArray(matrix));
        } else if (s instanceof ImageSignal) {
            //myFrame.showImage(((ImageSignal)s).getImage());
            myCanvas.showImage(((ImageSignal)s).getImage());
        }
    }


    private ImageProducer convertGrayToArray(int[][] R)
    {
        int imageWidth = R.length;
        int imageHeight = R[0].length;

        int[] array = new int[imageWidth * imageHeight];

        int index = 0;
        for (int y = 0; y < imageHeight; y++) {
            for (int x = 0; x < imageWidth; x++) {
                array[index] = -16777216 | (R[x][y] << 16) | (R[x][y] << 8) | R[x][y];
                index++;
            }
        }

        MemoryImageSource image = new MemoryImageSource(imageWidth,imageHeight,array,0,imageWidth);
        return image;
    }

    private ImageProducer convertToArray(int[][] R)
    {
        int imageWidth = R.length;
        int imageHeight = R[0].length;

        int[] array = new int[imageWidth * imageHeight];

        int index = 0;
        for (int y = 0; y < imageHeight; y++) {
            for (int x = 0; x < imageWidth; x++) {
                array[index] = (R[x][y] | 0xff000000);
                index++;
            }
        }

        MemoryImageSource image = new MemoryImageSource(imageWidth,imageHeight,array,0,imageWidth);
        return image;
    }
  /*
    public class ImageFrameAdapter extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
            e.getWindow().hide();
        }
    }
    */
/*
    public class ImageFrame extends Frame {

        private Image image;

        public void showImage(ImageProducer ip) {
            image = this.createImage(ip);
            int width = image.getWidth(this);
            int height = image.getHeight(this);
            setSize(width,height);
            repaint();
        }

        public void showImage(Image img) {
            image = img;
            int width = image.getWidth(this);
            int height = image.getHeight(this);
            setSize(width,height);
            repaint();
        }

        public void paint(Graphics g) {
            if (image != null) {
                g.drawImage(image,0,0,null);
            }
        }

        public boolean imageUpdate(Image img, int infoflags, int x, int y,
                               int width, int height) {
            setSize(width,height);
            return false;
        }

    }
*/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -