gpt4 book ai didi

java - 为什么我的位图填充字节不同步,而我确信它应该没问题?

转载 作者:行者123 更新时间:2023-12-01 21:47:16 25 4
gpt4 key购买 nike

我试图将十六进制字符串作为二进制字节打印到位图中(按顺序)例如: a6c832bac v 1010 v 像素阵列中的 FFFFFF000000FFFFFF000000 (b,g,r)。

我认为问题出在“填充”上我可以接受将其打印到像素阵列,但正如您所期望的,图像应该是黑/白,但是存在未对准,并且我的图像是彩色的......

我尝试过四处搜索,也尝试过打乱顺序。我是java新手,所以我不知道是否缺少任何东西。我实在是想不通

这是标题代码,我在其中初始化填充大小,然后将标题信息写入文件,我知道这是正确的,因为所有图像查看器都可以加载我的位图。

int headers[] = new int[13];
int WIDTH = (int)Math.sqrt(hexstring.length()*4) + 1;
int HEIGHT = WIDTH;
int extrabytes, paddedsize, offset;
int bit = 0;
extrabytes = 4 - ((WIDTH * 3) % 4);
if(extrabytes == 4) extrabytes = 0;
paddedsize = ((WIDTH * 3) + extrabytes) * HEIGHT;

这是像素数组绘制代码。

        int z = 0;
int x = 0;
for (int yy = HEIGHT - 1; yy >= 0; yy--) { // BMP PIXEL ARRAY, Bottom -> Top, Left -> Right
for (int xx = 0; xx <= WIDTH - 1; xx++) {
if(z < hexstring.length()){ // print valuable chars
String bit_string = String.format("%4s", Integer.toBinaryString(Integer.parseInt(Character.toString(hexstring.charAt(z)), 16))).replace(" ", "0");
byte[] bits = bit_string.getBytes();
System.out.println("BIT STRING: " + bit_string);
for(int w = 0; w < 4; w++){
bit = (bits[w]-48)*0xFF;
System.out.println(bit);
outfile.write(bit);
outfile.write(bit);
outfile.write(bit);
}
z++;
} else { //print eot
outfile.write(128);
outfile.write(128);
outfile.write(128);
}
}
if (extrabytes != 0) {
for (int nnn = 1; nnn <= extrabytes; nnn++)
{
System.out.println("PADDING");
outfile.write(0); // can be any value
}
}
}

我不知道如何包含图像,但我可以提供我有目的的探测吗?

BIT STRING: 0110
0
255
255
0
BIT STRING: 1000
255
0
0
0
BIT STRING: 1000
255
0
0
0
BIT STRING: 1011
255
0
255
255
BIT STRING: 0011
0
0
255
255
BIT STRING: 1010
255
0
255
0
BIT STRING: 1111
255
255
255
255
BIT STRING: 1001
255
0
0
255
BIT STRING: 0011
0
0
255
255
BIT STRING: 1011
255
0
255
255
BIT STRING: 1110
255
255
255
0
BIT STRING: 0001
0
0
0
255
BIT STRING: 1010
255
0
255
0
BIT STRING: 1110
255
255
255
0
BIT STRING: 0100
0
255
0
0
BIT STRING: 0010
0
0
255
0
BIT STRING: 1110
255
255
255
0
BIT STRING: 0010
0
0
255
0
PADDING
PADDING
BIT STRING: 1000
255
0
0
0
BIT STRING: 1111
255
255
255
255
BIT STRING: 0100
0
255
0
0
BIT STRING: 0010
0
0
255
0
BIT STRING: 1111
255
255
255
255
BIT STRING: 0011
0
0
255
255
BIT STRING: 1100
255
255
0
0
BIT STRING: 0110
0
255
255
0
BIT STRING: 1101
255
255
0
255
BIT STRING: 1101
255
255
0
255
BIT STRING: 0001
0
0
0
255
BIT STRING: 1000
255
0
0
0
BIT STRING: 1101
255
255
0
255
BIT STRING: 0010
0
0
255
0
BIT STRING: 1000
255
0
0
0
BIT STRING: 0010
0
0
255
0
BIT STRING: 0111
0
255
255
255
BIT STRING: 1010
255
0
255
0
PADDING
PADDING
BIT STRING: 0010
0
0
255
0
BIT STRING: 0001
0
0
0
255
BIT STRING: 1010
255
0
255
0
BIT STRING: 1010
255
0
255
0
BIT STRING: 1010
255
0
255
0
BIT STRING: 0111
0
255
255
255
BIT STRING: 1000
255
0
0
0
BIT STRING: 0000
0
0
0
0
BIT STRING: 0110
0
255
255
0
BIT STRING: 0110
0
255
255
0
BIT STRING: 0110
0
255
255
0
BIT STRING: 1000
255
0
0
0
BIT STRING: 1111
255
255
255
255
BIT STRING: 0000
0
0
0
0
BIT STRING: 1010
255
0
255
0
BIT STRING: 0101
0
255
0
255
BIT STRING: 1110
255
255
255
0
BIT STRING: 0010
0
0
255
0
PADDING
PADDING
BIT STRING: 1010
255
0
255
0
BIT STRING: 1000
255
0
0
0
BIT STRING: 1100
255
255
0
0
BIT STRING: 0111
0
255
255
255
BIT STRING: 1100
255
255
0
0
BIT STRING: 1100
255
255
0
0
BIT STRING: 1010
255
0
255
0
BIT STRING: 0011
0
0
255
255
BIT STRING: 0101
0
255
0
255
BIT STRING: 0111
0
255
255
255
BIT STRING: 1110
255
255
255
0
BIT STRING: 0010
0
0
255
0
BIT STRING: 0000
0
0
0
0
BIT STRING: 1000
255
0
0
0
BIT STRING: 0001
0
0
0
255
BIT STRING: 1001
255
0
0
255
BIT STRING: 1000
255
0
0
0
BIT STRING: 0001
0
0
0
255
PADDING
PADDING
BIT STRING: 1111
255
255
255
255
BIT STRING: 0111
0
255
255
255
BIT STRING: 0001
0
0
0
255
BIT STRING: 0100
0
255
0
0
BIT STRING: 0001
0
0
0
255
BIT STRING: 0011
0
0
255
255
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
PADDING
EXTRA BYTES = 2
78 characters printed out of 78

最佳答案

答案是半复杂的,但显然问题就在于此。

for(int w = 0; w < 4; w++){
bit = (bits[w]-48)*0xFF;
System.out.println(bit);
outfile.write(bit);
outfile.write(bit);
outfile.write(bit);
}

```
for some reason writing to the file in this loop just was unpredictable, and i ended up just converting my large hexadecimal string to a full binary string byte by byte

关于java - 为什么我的位图填充字节不同步,而我确信它应该没问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58780518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com