优化Black& Java中的白色过滤器

时间:2018-01-18 19:30:30

标签: java multithreading optimization filter rgb

我已经实施了一种应用Black& amp;白色的图像,我想知道什么是相同的算法,但使用线程的最佳替代?

public static void blackAndWhite()
{
        for(int x = 0; x < img.getWidth(); x++)
        {
            for(int y = 0; y < img.getHeight(); y++)
            {
                int rgb = Main.img.getRGB(x, y);
                Color c = new Color(rgb);
                int grey = (int) (0.299 * c.getRed() + 0.587 * c.getGreen() + 0.114*c.getBlue());
                Color c2 = new Color(grey, grey, grey);
                Main.img.setRGB(x, y, c2.getRGB());
            }
        }

}

我想过做这样的事情,但是我得到关于x或y的'final'状态的错误

Thread t = new Thread(() -> {
            for(int x = 0; x < img.getWidth(); x++)
        {
            for(int y = 0; y < img.getHeight(); y++)
            {
                int rgb = Main.img.getRGB(x, y);
                Color c = new Color(rgb);
                int grey = (int) (0.299 * c.getRed() + 0.587 * c.getGreen() + 0.114*c.getBlue());
                Color c2 = new Color(grey, grey, grey);
                Main.img.setRGB(x, y, c2.getRGB());
            }
        }
        });
        t.start();
        try{
            t.join();
        }catch(InterruptedException ie){
            System.out.println(ie.getMessage());
        }

谢谢!

0 个答案:

没有答案