Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 修改像素后如何使用setRGB()?我需要使用十六进制吗?_Image Processing_Pixel_Java 2d - Fatal编程技术网

Image processing 修改像素后如何使用setRGB()?我需要使用十六进制吗?

Image processing 修改像素后如何使用setRGB()?我需要使用十六进制吗?,image-processing,pixel,java-2d,Image Processing,Pixel,Java 2d,对于我的项目,我必须读取图像中的每个像素,对每个像素执行数学运算,然后在更新的图像中显示修改后的像素的结果。对于这个例子,我取每个像素的平方根 public void rootCalc(){//go through the rows and columns for(int x=grayscale_orig.getWidth() - 1; x >= 1; x--) { for (int y = grayscale_orig.getH

对于我的项目,我必须读取图像中的每个像素,对每个像素执行数学运算,然后在更新的图像中显示修改后的像素的结果。对于这个例子,我取每个像素的平方根

public void rootCalc(){//go through the rows and columns                            for(int x=grayscale_orig.getWidth() - 1; x >= 1; x--)
 {
  for (int y = grayscale_orig.getHeight() - 1; y >= 0; y--)
  {
      //this is the pixel array
      int[] rgb1 = getColors(grayscale_orig.getRGB(x, y));
      for(int g=0; g<rgb1.length;g++) 
      {   //take the square root of each pixel value
       v=255*(Math.sqrt(rgb1[g])/Math.sqrt(255));
//scale the squared value back into the 0-255 range and set the value
       grayscale.setRGB(x,y,(int)v);
      }
  }
 }}
public void rootCalc(){//检查(int x=grayscale\u orig.getWidth()-1;x>=1;x--)的行和列
{
对于(int y=grayscale\u orig.getHeight()-1;y>=0;y--)
{
//这是像素阵列
int[]rgb1=getColors(灰度源getRGB(x,y));
对于(int g=0;g来说,没有“十六进制”这样的东西——int只是一个数字。我们通常在代码中使用十进制表示法,它实际上只是保存了二进制系统——然而,它只是一个数字,你不能仅仅“将其改成十六进制”

但是,您的代码有一个问题。您对颜色的红色部分调用了一次setRGB,然后对颜色的绿色部分调用了一次,然后对蓝色部分调用了一次(我想无论如何都是这个顺序)。但是,setRGB需要一个整数来表示整个颜色

您可以手工计算这样一个整数,但更容易的方法是从颜色的这些分区中创建一个颜色对象,然后通过调用颜色的getRGB来获取要提供给setGRB的值