我已經成功地從compareHexaRGB方法中檢索RGB像素值。由於輸出包含空字符,輸出看起來並不令人信服。我怎樣才能消除它們?檢索到的值有一個空值。如何消除它們?
其次,當我試圖結合String [] [] char 1 + char 2時,我得到一個錯誤,指出它是「+」類型的錯誤操作數。但我想結合2字符串,以便我能夠將其轉換爲ASCII字符。
下面是compareHexaRGB方法的代碼:
public class compareHexaRGB
{
private static int w;
private static int h;
private static BufferedImage img;
private static BufferedImage img2;
private static String[][] check_hex2;
private static String[][] check_hex4;
private static String[][] message;
public static void compareHexaRGB(BufferedImage image, BufferedImage image2, int width, int height) throws IOException
{
w = width;
h = height;
img = image;
img2 = image2;
}
public void check() throws IOException
{
getPixelRGB1 pixel = new getPixelRGB1();
getPixelData1 newPD = new getPixelData1();
int[] rgb;
int count = 0;
int[][] pixelData = new int[w * h][3];
check_hex2 = new String[w][h];
check_hex4 = new String[w][h];
for(int i = 0; i < w; i++)
{
for(int j = 0; j < h; j++)
{
rgb = newPD.getPixelData(img, i, j);
for(int k = 0; k < rgb.length; k++)
{
pixelData[count][k] = rgb[k];
}
if(pixel.display_imgHex2()[i][j].equals(pixel.display_img2Hex2()[i][j]))
{
System.out.println("\nPixel values at position 2 are the same." + "\n" + pixel.display_imgHex2()[i][j] + " " + pixel.display_img2Hex2()[i][j]);
}
if(pixel.display_imgHex4()[i][j].equals(pixel.display_img2Hex4()[i][j]))
{
System.out.println("\nPixel values at position 4 are the same." + "\n" + pixel.display_imgHex4()[i][j] + " " + pixel.display_img2Hex4()[i][j]);
}
if(!pixel.display_imgHex2()[i][j].equals(pixel.display_img2Hex2()[i][j]))
{
System.out.println("\nPixel values at position 2 are not the same." + "\n" + pixel.display_imgHex2()[i][j] + " " + pixel.display_img2Hex2()[i][j]);
check_hex2[i][j] = pixel.display_img2Hex2()[i][j];
System.out.println("\nOutput Hex 2: " + check_hex2[i][j]);
}
if(!pixel.display_imgHex4()[i][j].equals(pixel.display_img2Hex4()[i][j]))
{
System.out.println("\nPixel values at position 4 are not the same." + "\n" + pixel.display_imgHex4()[i][j] + " " + pixel.display_img2Hex4()[i][j]);
check_hex4[i][j] = pixel.display_img2Hex4()[i][j];
System.out.println("\nOutput Hex 4: " + check_hex4[i][j]);
}
if(!pixel.display_imgHex2()[i][j].equals(pixel.display_img2Hex2()[i][j]) || (!pixel.display_imgHex4()[i][j].equals(pixel.display_img2Hex4()[i][j])))
{
System.out.println("\nOne of the pixel values at position 2 and 4 are not the same." + "\n" + pixel.display_imgHex2()[i][j] + " " + pixel.display_img2Hex2()[i][j] + "\n" + pixel.display_imgHex4()[i][j] + " " + pixel.display_img2Hex4()[i][j]);
if(!pixel.display_imgHex2()[i][j].equals(pixel.display_img2Hex2()[i][j]) || (pixel.display_imgHex2()[i][j].equals(pixel.display_img2Hex2()[i][j])))
{
check_hex2[i][j] = pixel.display_img2Hex2()[i][j];
System.out.println("\nOutput Hex 2: " + check_hex2[i][j]);
}
if(!pixel.display_imgHex4()[i][j].equals(pixel.display_img2Hex4()[i][j]) || (pixel.display_imgHex4()[i][j].equals(pixel.display_img2Hex4()[i][j])))
{
check_hex4[i][j] = pixel.display_img2Hex4()[i][j];
System.out.println("\nOutput Hex 4: " + check_hex4[i][j]);
}
}
count++;
System.out.println("\nOutput Count: " + count);
}
}
}
public String[][] getCheck_hex2()
{
return check_hex2;
}
public String[][] getCheck_hex4()
{
return check_hex4;
}
}
代碼extractMessage方法:
public class extractMessage
{
private static String character;
private static String[][] char1;
private static String[][] char2;
private static int w;
private static int h;
private static String[][] in;
public static void extractMessage(int width, int height, String[][] inn)
{
character = "";
w = width;
h = height;
in = inn;
}
public static void printString2DArray(String[][] inn)
{
for (int i = 0; i < inn.length; i++)
{
for(int j = 0; j < inn[i].length; j++)
{
if (i != 0 && j == 0)
{
System.out.print(" ");
}
System.out.println(inn[i][j]);
}
}
}
public static void charExtract()
{
compareHexaRGB hexRGB = new compareHexaRGB();
char1 = hexRGB.getCheck_hex2();
char2 = hexRGB.getCheck_hex4();
String[][] combine = char1 + char2;
System.out.println("Char 1: ");
printString2DArray(char1);
System.out.println("Char 2: ");
printString2DArray(char2);
}
}
OUTPUT:
Char 1:
null
null
null
null
null
null
null
null
6
6
null
null
6
null
null
null
null
null
Char 2:
null
null
null
null
null
null
null
null
2
3
null
null
1
null
null
null
null
null
任何建議或糾正我將高度讚賞!
,你說,我要補充的地方來保存字符。我可以做這樣的事情 - > if(pixel.display_imgHex2()[i] [j] .equals(pixel.display_img2Hex2()[i] [j])) { System.out.println(「\ nPixel 「+」\ n「+ pixel.display_imgHex2()[i] [j] +」「+ pixel.display_img2Hex2()[i] [j]); not_stega2 [i] [j] = pixel.display_img2Hex2()[i] [j]; }?還是我做錯了? – user3116040