java - 如何在 python 或 java 中显示图像的像素数组???帮我

标签 java python

我是 python 和 java 新手。我在类里面布置了显示图像中的像素阵列图像的任务。请帮我?? 谢谢

最佳答案

您是否想获取每个像素颜色的二维数组?在Java BufferedImage类中,有一个方法:

getRGB(int x, int y)

因此,您可以循环遍历每个像素并将其添加到数组中,如下所示:

int[][] array = new int[img.getWidth()][img.getHeight()];
for (int i = 0; i < img.getWidth(); i++) {
   for (int j = 0; i < img.getHeight(); j++) {
      array[i][j] = img.getRGB(i, j);
   }
}

这将为您提供每个像素的 RGB 值的 2D 数组。

关于java - 如何在 python 或 java 中显示图像的像素数组???帮我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5427198/

相关文章:

java - 扫描程序在使用next()或nextFoo()之后跳过nextLine()吗?

java - 值对象中的线程安全

python - 我怎样才能获得List.__gt__()函数的源实现

python - Django 电子邮件 : Client does not have permission to send as this sender

python - 当 dtype 为 object 时使用 numpy 函数

java - 尝试使用 java 中的循环在数组中创建 100 个对象

java - BridJ:无法获取方法的地址

python - 以编程方式更新 Zapier 存储

python - 类型错误 : force_login() missing 1 required positional argument: 'user'

java - 泛型定义