简体   繁体   English

BufferedImage类型的方法getRGB(int,int)不适用于参数(..)

[英]The method getRGB(int, int) in the type BufferedImage is not applicable for the arguments (..)

I have a TIFF image with some "out of order" detectors (with null columns of pixels), and a previous created Array with index of column and nb of pixel null . 我有一个带有一些“乱序”检测器的TIFF图像(像素的null列),以及先前创建的Array,其列的索引为nb,像素为null I am trying to build a code that, scanning image, correct it applying a simple interpolation: 我正在尝试构建一个代码,以扫描图像,并通过简单的插值对其进行纠正:

image.setRGB = ((row + numOfDetectors) + (row - 1)/ 2);

of neighboring pixels when find null pixel (reading the informations in Array list). 找到null像素(读取“数组”列表中的信息)时相邻像素的像素数。

But I'm having a bit of problems with the image.setRGB method. 但是我在image.setRGB方法上有一些问题。

import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class ArrayInterpolatorNew {


    // public static void main(String[] args) {
    private static void getPixelData(BufferedImage tif) {
        try { 

            String currentDir = new File(".").getAbsolutePath();
            System.out.println ("Current directory: " + currentDir);

            //read image file
            File file1 = new File("E:\\ByPass_PAN_C.tif");
            BufferedImage image1 = ImageIO.read(file1);

            // Firstly get a pixel
            int pixelValue = image1.getRGB(tif.getWidth(), tif.getHeight());

            // Developer may get all the pixels
            int width  = tif.getWidth(null);
            int height = tif.getHeight(null);
            int[] result = new int[height*width];
            int offset;


            image1.getRGB(0, 0, width, height, result, 0);

            //write file
            File file = new File("Resources/ByPass_PAN_C_interpol.tif"); // The file to save to.
            String format = "TIF"; // Example: "PNG" or "JPG"
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);


            final byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
            final int firstRow = 1;
            final int numOfDetectors = 1;
            int row = tif.getWidth();
            int col = tif.getHeight();
            //int[][] pixels = new int[w][h];

            for (int j = 0; j < row; j++) 

                for (int i = 0; i < col; i++) 
                    //result[] = image.getRGB(row, col);

                    for(int J = 0; J < firstRow; J++) 
                    {   
                        if (row != J){
                            // set a pixel
                            image.setRGB(row, col, pixelValue);
                            //pixels[row] = [row][col];

                        if (row == J){
                            System.out.println("x,y: " + row + ", " + col + "num of Detectors: " + numOfDetectors);
                            //image.setRGB = ((row + numOfDetectors) + (row - 1)/ 2);
                            //tif.setRGB(pixelNoInterpol | pixelInterpol);

                        if (row == J && numOfDetectors > 20){
                            System.out.println("x,y: " + row + ", " + col + "num of Detectors: " + numOfDetectors + "then > 20");
                            image.setRGB(row, col, pixelValue);
                            }
                        }
                    }
                    try {
                        ImageIO.write(image, format, file);
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally { System.out.println("Images were written succesfully.");}  
                    System.out.println("rest of the code...");
                    }
            }  finally {
                }     
            }
}

Your method signature is wrong. 您的方法签名错误。 It's either 要么

getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)

Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, from a portion of the image data. 从图像数据的一部分返回默认RGB颜色模型(TYPE_INT_ARGB)和默认sRGB颜色空间中的整数像素数组。

or 要么

getRGB (int, int)

You are using the incorrect argument list for getRGB: 您为getRGB使用了不正确的参数列表:

image1.getRGB(0, 0, width, height, result, 0);

try 尝试

 image1.getRGB(0, 0, width, height, result, 0, scansize);

try this 尝试这个

you are getting pixelValue of last cell. 您正在获取最后一个单元格的pixelValue。 so get every cell pixel 所以得到每个细胞像素

  int x1 = image1.getWidth();
  int y1 = image1.getHeight();
        BufferedImage dummy = new BufferedImage(x1, y1, 13);//BufferedImage.TYPE_INT_ARGB);

        for ( int rows = 0; rows < x1; rows++ ) {
             for ( int columns = 0; columns < y1; columns++ ){


                 int firstImg_Pixel = image1.getRGB( rows, columns );

                   //  dummy.setRGB(rows, columns, Color.red.getRed());
                 }
         }      

        // ImageIO.write(dummy, "jpeg", new File("D:\\Screenshots\\A-Image\\uuu.jpg"));

The problem is here: 问题在这里:

image1.getRGB(0, 0, width, height, result, 0);

You are missing the last parameter, scansize . 您缺少最后一个参数scansize You can use the width as the scansize , so it would be: 您可以使用width作为scansize ,因此它将是:

image1.getRGB(0, 0, width, height, result, 0, width);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型中的方法不适用于参数(int) - The method in the type is not applicable for the arguments (int) 类型X中的方法X不适用于参数(int) - The method X in the type X is not applicable for the arguments (int) main类型的方法(double [])不适用于参数(int []) - The method (double[]) in the type main is not applicable for the arguments (int[]) ArrayBoss 类型中的方法 (int[]) 不适用于参数 () - The method (int[]) in the type ArrayBoss is not applicable for the arguments () FragmentTransaction类型的方法add(int,Fragment)不适用于参数(int,WeatherFragment) - The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, WeatherFragment) prosedure_jsp类型的pro(int,int)方法不适用于参数() - The method pro(int, int) in the type prosedure_jsp is not applicable for the arguments () Arrays 类型中的 asList(T[]) 方法不适用于参数 (int, int) - The method asList(T[]) in the type Arrays is not applicable for the arguments (int, int) PreparedStatement 类型中的 setString(int, String) 方法不适用于参数 (int, String[]) - The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, String[]) ArrayList 类型中的方法 set(int, Int)<int> 不适用于 arguments (int, int) 长度无法解析或不是字段</int> - The method set(int, Int) in the type ArrayList<Int> is not applicable for the arguments (int, int) length cannot be resolved or is not a field 方法 sum(int, int, int, int) 不适用于参数 (int) - The method sum(int, int, int, int) is not applicable for the arguments (int)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM