Record your dynamic beauty - Java video filter

We all know that videos cannot be photoshopped, so once you learn the video filters, you will be the most beautiful boy!

Create a filter class;

In fact, the specific idea is very similar to the previous image filter, so I will post the code directly.

public BufferedImage grayimage(Graphics g,BufferedImage image){
    int width=image.getWidth();
    int height= image.getHeight();
    for(int i=0;i<width;i++){
        for(int j=0;j<height;j++){
             rgb=image.getRGB(i,j);
             depart(rgb);
             gray=(int)(0.3*r+0.59*ge+0.11*b);
             addall(gray,gray,gray);
             image.setRGB(i,j,rgb);
        }
    }
    return image;
}//Ash filter

It is worth noting that the setRGB method can help me get the picture we want.

At the same time, pay attention to the return value for subsequent use.

As for the special mosaic effect, you need to create a new picture and then draw it with the brush of the cached picture;

 public BufferedImage masiimage(Graphics g,BufferedImage image){
        int width=image.getWidth();
        int height=image.getHeight();
        BufferedImage newImage = new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB);
        Graphics bf= newImage.getGraphics();
        for(int i=0;i<width;i+=5) {
            for (int j = 0; j < height; j += 5) {
                rgb = image.getRGB(i, j);
                Color cl = new Color(rgb);
                bf.setColor(cl);
                bf.fillRect( i, j, 5, 5);
            }
        }
        return newImage;
    }//马赛克滤镜

After completing these, we use switch to improve the run method in multi-threading and modify the logic of the listener;

At the same time, use JPanel to make our interface more beautiful:

public void ui() {
        JFrame jf=new JFrame();
        jf.setTitle("VIDEO");
        jf.setSize(2000,2000);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//建立窗口

        this.setBackground(Color.LIGHT_GRAY);
        JPanel btnpnl=new JPanel();
        btnpnl.setBackground(Color.white);
        Dimension dim=new Dimension(300,200);
        btnpnl.setPreferredSize(dim);
        btnUI(btnname,btnpnl);

        jf.add(this,BorderLayout.CENTER);
        jf.add(btnpnl,BorderLayout.WEST);

        jf.setLocationRelativeTo(null);
        jf.setVisible(true);
        Graphics g=this.getGraphics();
        ll.setGraphics(g);
    }

The final results are as follows:

Of course, after using multithreading, remember to let the run method end 

Guess you like

Origin blog.csdn.net/AkinanCZ/article/details/125880377