gpt4 book ai didi

java - 以编程方式更改 BMP 文件

转载 作者:行者123 更新时间:2023-12-01 19:05:55 27 4
gpt4 key购买 nike

我想加载一个 bmp 文件(用 Java 语言)并在 java 程序的语法中操作图像数据。我怎样才能做到这一点?我尝试只加载图像,如下所示:

   public static void main(String[] args) {
System.out.println("START");
loadbitmap lbm = new loadbitmap();
lbm.loadBMPFile();
System.out.println("END");
}

private void loadBMPFile()
{
{
try{

FileInputStream fstream = new FileInputStream("sample_fingerprint_grayscale.bmp");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String inputString;
while ((inputString = br.readLine()) != null) {

readBMPFile.add(inputString);
}
in.close();
}
catch (Exception e){
System.out.println("IN ERROR");
System.err.println("Error: " + e.getMessage());
}
System.out.println("IN loadBMPFile");
System.out.println("BMP size is " + readBMPFile.size());
System.out.println(readBMPFile.get(2));
}
}
}

但是当我检查数据时,它并不真正存在。我在这方面是个菜鸟,所以任何正确方向的观点都会受到赞赏。

这是输出:

START
IN loadBMPFile
BM¸U

(At this point there is a large amount of gibberish characters that won't paste into Stack Overflow)

END

我有一个十六进制阅读器(Frhed),可以将这些字符格式化为十六进制格式,我希望我可以将它们放入数组列表中并从那里操作它们。

这是十六进制读取器输出:

BM<bh:b8>U<bh:01><bh:00><bh:00><bh:00><bh:00><bh:00>6<bh:04><bh:00><bh:00>(<bh:00><bh:00><bh:00><bh:f0><bh:00><bh:00><bh:00><bh:98><bh:fe><bh:ff><bh:ff><bh:01><bh:00><bh:08><bh:00><bh:00><bh:00><bh:00><bh:00><bh:82>Q<bh:01><bh:00><bh:12><bh:0b><bh:00><bh:00><bh:12><bh:0b><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:01><bh:01><bh:01><bh:00><bh:02><bh:02><bh:02><bh:00><bh:03><bh:03><bh:03><bh:00><bh:04><bh:04><bh:04><bh:00><bh:05><bh:05><bh:05><bh:00><bh:06><bh:06><bh:06><bh:00><bh:07><bh:07><bh:07><bh:00><bh:08><bh:08><bh:08><bh:00><bh:09><bh:09><bh:09><bh:00>


<bh:00><bh:0b><bh:0b><bh:0b><bh:00><bh:0c><bh:0c><bh:0c><bh:00>


<bh:00><bh:0e><bh:0e><bh:0e><bh:00><bh:0f><bh:0f><bh:0f><bh:00><bh:10><bh:10><bh:10><bh:00><bh:11><bh:11><bh:11><bh:00><bh:12><bh:12><bh:12><bh:00><bh:13><bh:13><bh:13><bh:00><bh:14><bh:14><bh:14><bh:00><bh:15><bh:15><bh:15><bh:00><bh:16><bh:16><bh:16><bh:00><bh:17><bh:17><bh:17><bh:00><bh:18><bh:18><bh:18><bh:00><bh:19><bh:19><bh:19><bh:00><bh:1a><bh:1a><bh:1a><bh:00><bh:1b><bh:1b><bh:1b><bh:00><bh:1c><bh:1c><bh:1c><bh:00><bh:1d><bh:1d><bh:1d><bh:00><bh:1e><bh:1e><bh:1e><bh:00><bh:1f><bh:1f><bh:1f><bh:00> <bh:00>!!!<bh:00>"""<bh:00>###<bh:00>$$$<bh:00>%%%<bh:00>&&&<bh:00>'''<bh:00>(((<bh:00>)))<bh:00>***<bh:00>+++<bh:00>,,,<bh:00>---<bh:00>...<bh:00>///<bh:00>000<bh:00>111<bh:00>222<bh:00>333<bh:00>444<bh:00>555<bh:00>666<bh:00>777<bh:00>888<bh:00>999<bh:00>:::<bh:00>;;;<bh:00>\<\<\<<bh:00>===<bh:00>>>><bh:00>???<bh:00>@@@<bh:00>AAA<bh:00>BBB<bh:00>CCC<bh:00>DDD<bh:00>EEE<bh:00>FFF<bh:00>GGG<bh:00>HHH<bh:00>III<bh:00>JJJ<bh:00>KKK<bh:00>LLL<bh:00>MMM<bh:00>NNN<bh:00>OOO<bh:00>PPP<bh:00>QQQ<bh:00>RRR<bh:00>SSS<bh:00>TTT<bh:00>UUU<bh:00>VVV<bh:00>WWW<bh:00>XXX<bh:00>YYY<bh:00>ZZZ<bh:00>[[[<bh:00>\\\\\\<bh:00>]]]<bh:00>^^^<bh:00>___<bh:00>```<bh:00>aaa<bh:00>bbb<bh:00>ccc<bh:00>ddd<bh:00>eee<bh:00>fff<bh:00>ggg<bh:00>hhh<bh:00>iii<bh:00>jjj<bh:00>kkk<bh:00>lll<bh:00>mmm<bh:00>nnn<bh:00>ooo<bh:00>ppp<bh:00>qqq<bh:00>rrr<bh:00>sss<bh:00>ttt<bh:00>uuu<bh:00>vvv<bh:00>www<bh:00>xxx<bh:00>yyy<bh:00>zzz<bh:00>{{{<bh:00>|||<bh:00>}}}<bh:00>~~~<bh:00><bh:7f><bh:7f><bh:7f><bh:00><bh:80><bh:80><bh:80><bh:00><bh:81><bh:81><bh:81><bh:00><bh:82><bh:82><bh:82><bh:00><bh:83><bh:83><bh:83><bh:00><bh:84><bh:84><bh:84><bh:00><bh:85><bh:85><bh:85><bh:00><bh:86><bh:86><bh:86><bh:00><bh:87><bh:87><bh:87><bh:00><bh:88><bh:88><bh:88><bh:00><bh:89><bh:89><bh:89><bh:00><bh:8a><bh:8a><bh:8a><bh:00><bh:8b><bh:8b><bh:8b><bh:00><bh:8c><bh:8c><bh:8c><bh:00><bh:8d><bh:8d><bh:8d><bh:00><bh:8e><bh:8e><bh:8e><bh:00><bh:8f><bh:8f><bh:8f><bh:00><bh:90><bh:90><bh:90><bh:00><bh:91><bh:91><bh:91><bh:00><bh:92><bh:92><bh:92><bh:00><bh:93><bh:93><bh:93><bh:00><bh:94><bh:94><bh:94><bh:00><bh:95><bh:95><bh:95><bh:00><bh:96><bh:96><bh:96><bh:00><bh:97><bh:97><bh:97><bh:00><bh:98><bh:98><bh:98><bh:00><bh:99><bh:99><bh:99><bh:00><bh:9a><bh:9a><bh:9a><bh:00><bh:9b><bh:9b><bh:9b><bh:00><bh:9c><bh:9c><bh:9c><bh:00><bh:9d><bh:9d><bh:9d><bh:00><bh:9e><bh:9e><bh:9e><bh:00><bh:9f><bh:9f><bh:9f><bh:00><bh:a0><bh:a0><bh:a0><bh:00><bh:a1><bh:a1><bh:a1><bh:00><bh:a2><bh:a2><bh:a2><bh:00><bh:a3><bh:a3><bh:a3><bh:00><bh:a4><bh:a4><bh:a4><bh:00><bh:a5><bh:a5><bh:a5><bh:00><bh:a6><bh:a6><bh:a6><bh:00><bh:a7><bh:a7><bh:a7><bh:00><bh:a8><bh:a8><bh:a8><bh:00><bh:a9><bh:a9><bh:a9><bh:00><bh:aa><bh:aa><bh:aa><bh:00><bh:ab><bh:ab><bh:ab><bh:00><bh:ac><bh:ac><bh:ac><bh:00><bh:ad><bh:ad><bh:ad><bh:00><bh:ae><bh:ae><bh:ae><bh:00><bh:af><bh:af><bh:af><bh:00><bh:b0><bh:b0><bh:b0><bh:00><bh:b1><bh:b1><bh:b1><bh:00><bh:b2><bh:b2><bh:b2><bh:00><bh:b3><bh:b3><bh:b3><bh:00><bh:b4><bh:b4><bh:b4><bh:00><bh:b5><bh:b5><bh:b5><bh:00><bh:b6><bh:b6><bh:b6><bh:00><bh:b7><bh:b7><bh:b7><bh:00><bh:b8><bh:b8><bh:b8><bh:00><bh:b9><bh:b9><bh:b9><bh:00><bh:ba><bh:ba><bh:ba><bh:00><bh:bb><bh:bb><bh:bb><bh:00><bh:bc><bh:bc><bh:bc><bh:00><bh:bd><bh:bd><bh:bd><bh:00><bh:be><bh:be><bh:be><bh:00><bh:bf><bh:bf><bh:bf><bh:00><bh:c0><bh:c0><bh:c0><bh:00><bh:c1><bh:c1><bh:c1><bh:00><bh:c2><bh:c2><bh:c2><bh:00><bh:c3><bh:c3><bh:c3><bh:00><bh:c4><bh:c4><bh:c4><bh:00><bh:c5><bh:c5><bh:c5><bh:00><bh:c6><bh:c6><bh:c6><bh:00><bh:c7><bh:c7><bh:c7><bh:00><bh:c8><bh:c8><bh:c8><bh:00><bh:c9><bh:c9><bh:c9><bh:00><bh:ca><bh:ca><bh:ca><bh:00><bh:cb><bh:cb><bh:cb><bh:00><bh:cc><bh:cc><bh:cc><bh:00><bh:cd><bh:cd><bh:cd><bh:00><bh:ce><bh:ce><bh:ce><bh:00><bh:cf><bh:cf><bh:cf><bh:00><bh:d0><bh:d0><bh:d0><bh:00><bh:d1><bh:d1><bh:d1><bh:00><bh:d2><bh:d2><bh:d2><bh:00><bh:d3><bh:d3><bh:d3><bh:00><bh:d4><bh:d4><bh:d4><bh:00><bh:d5><bh:d5><bh:d5><bh:00><bh:d6><bh:d6><bh:d6><bh:00><bh:d7><bh:d7><bh:d7><bh:00><bh:d8><bh:d8><bh:d8><bh:00><bh:d9><bh:d9><bh:d9><bh:00><bh:da><bh:da><bh:da><bh:00><bh:db><bh:db><bh:db><bh:00><bh:dc><bh:dc><bh:dc><bh:00><bh:dd><bh:dd><bh:dd><bh:00><bh:de><bh:de><bh:de><bh:00><bh:df><bh:df><bh:df><bh:00><bh:e0><bh:e0><bh:e0><bh:00><bh:e1><bh:e1><bh:e1><bh:00><bh:e2><bh:e2><bh:e2><bh:00><bh:e3><bh:e3><bh:e3><bh:00><bh:e4><bh:e4><bh:e4><bh:00><bh:e5><bh:e5><bh:e5><bh:00><bh:e6><bh:e6><bh:e6><bh:00><bh:e7><bh:e7><bh:e7><bh:00><bh:e8><bh:e8><bh:e8><bh:00><bh:e9><bh:e9><bh:e9><bh:00><bh:ea><bh:ea><bh:ea><bh:00><bh:eb><bh:eb><bh:eb><bh:00><bh:ec><bh:ec><bh:ec><bh:00><bh:ed><bh:ed><bh:ed><bh:00><bh:ee><bh:ee><bh:ee><bh:00><bh:ef><bh:ef><bh:ef><bh:00><bh:f0><bh:f0><bh:f0><bh:00><bh:f1><bh:f1><bh:f1><bh:00><bh:f2><bh:f2><bh:f2><bh:00><bh:f3><bh:f3><bh:f3><bh:00><bh:f4><bh:f4><bh:f4><bh:00><bh:f5><bh:f5><bh:f5><bh:00><bh:f6><bh:f6><bh:f6><bh:00><bh:f7><bh:f7><bh:f7><bh:00><bh:f8><bh:f8><bh:f8><bh:00><bh:f9><bh:f9><bh:f9><bh:00><bh:fa><bh:fa><bh:fa><bh:00><bh:fb><bh:fb><bh:fb><bh:00><bh:fc><bh:fc><bh:fc><bh:00><bh:fd><bh:fd><bh:fd><bh:00><bh:fe><bh:fe><bh:fe><bh:00><bh:ff><bh:ff><bh:ff><bh:00><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff><bh:ff>

最佳答案

使用javax.imageio.ImageIO .

BufferedImage img = ImageIO.read(new File("... .bmp"));

BufferedImage 也可以更改,因此非常适合修改。

关于java - 以编程方式更改 BMP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10109420/

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