[英]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"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.