【问题标题】:I can not understand how this method works? [closed]我不明白这种方法是如何工作的? [关闭]
【发布时间】:2014-08-04 15:14:57
【问题描述】:

我不明白这个方法是如何工作的:

public DrawingCanvas(int[][] pixels, int rows, int cols){
    image = new BufferedImage(cols, rows, BufferedImage.TYPE_BYTE_GRAY);
    int pixel = 0;

    for (int r = 0; r < rows; r++){
        int col = 0;
        for (int c = 0; c < cols; c++){                 
            if(c+11 < cols){
                pixel = pixels[r][c+11];
            }
            else{
                pixel = pixels[r][col];
                col++;
            }
            image.setRGB(c, r, ((255<<24) | (pixel << 16) | (pixel << 8) | pixel)); 
        }
    }

【问题讨论】:

  • 您是在问您是否了解此方法的工作原理?
  • 哪一部分你不明白?
  • 它被执行了......有一个cpu和一个堆栈和东西......
  • 这个方法是什么意思?
  • 另外,它是一个构造函数。

标签: java swing awt


【解决方案1】:

此方法是使用 for 循环扫描图像(存储在 BufferedImage 的图像对象中)并使用 setRGB 方法逐像素更改颜色

【讨论】:

  • 感谢您的回答,并特别感谢所有投反对票的人...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-03
  • 1970-01-01
  • 1970-01-01
  • 2012-02-07
  • 1970-01-01
相关资源
最近更新 更多