|
本帖最后由 meigen 于 2014-10-10 20:19 编辑
接14楼,单色图的提取稍微麻烦些,他里面只有数据部分而缺少文件头,这个是比较头疼的事情
先用ebdump提取出词典文本(本文),然后在里面获取单色图的代码(<1F44>开头,<1F64>结尾)
可以看到
<1F44><0001><w=200,h=256>xxx<1F64>[0001A4BD:0027]
这里的w=200,h=256表示图片的尺寸,这个参数后面会用到
然后<1F64>后面的这一段[0001A4BD:0027]就是单色图数据地址了
先写个Demo 把所有地址都提取出来,顺便排一下序,去掉重复:
- static void getMonoTag(String f) {
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f+".mono.txt"), "UTF-8"));
- String line;
- ArrayList<String> monos = new ArrayList<String>();
- while (((line = reader.readLine()) != null)) {
- while (line.contains("<1F64>")) {
- line = line.substring(line.indexOf("<1F64>") + 6);
- monos.add(line.substring(0, 15));
- }
- }
- reader.close();
- String[] monoa = new String[monos.size()];
- monos.toArray(monoa);
- Arrays.sort(monoa);
- String last = "";
- for (int i=0; i<monoa.length; i++) {
- if (!monoa[i].equals(last))
- writer.write(monoa[i] + "\r\n");
- last = monoa[i];
- }
- writer.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
复制代码
得到了一个.mono.txt的文件
然后开始提取:
上面有提到w=200,h=256这两个参数,不过epwing好像弄反了,200是高,256是宽。 - -
提取过程中需要手动加上图像的文件头,可自行百度bmp文件格式
- static final int WIDTH = 256;
- static final int HEIGHT = 200;
- static final int WIDTH2 = 32;
- static final int SIZE = WIDTH2 * HEIGHT;
- static final int FILE_LEN = SIZE + 62;
- static byte[] filehead = {0x42, 0x4d,
- (byte) (FILE_LEN & 0xff), (byte) ((FILE_LEN >> 8) & 0xff), (byte) ((FILE_LEN >> 16) & 0xff), (byte) ((FILE_LEN >> 24) & 0xff),
- 0, 0, 0, 0, 0x3e, 0, 0, 0};
- static byte[] infohead = {0x28, 0, 0, 0,
- (byte) (WIDTH & 0xff), (byte) ((WIDTH >> 8) & 0xff), (byte) ((WIDTH >> 16) & 0xff), (byte) ((WIDTH >> 24) & 0xff),
- (byte) (HEIGHT & 0xff), (byte) ((HEIGHT >> 8) & 0xff), (byte) ((HEIGHT >> 16) & 0xff), (byte) ((HEIGHT >> 24) & 0xff),
- 1, 0, 1, 0, 0, 0, 0, 0,
- (byte) (SIZE & 0xff), (byte) ((SIZE >> 8) & 0xff), (byte) ((SIZE >> 16) & 0xff), (byte) ((SIZE >> 24) & 0xff),
- 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0};
- static void getMonoPic(String f, String m) {
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));
- BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(m+".txt"), "UTF-8"));
- OutputStream out = null;
- String line = "";
- String line2 = reader2.readLine();
- int block = 0;
- int block2 = Integer.parseInt(line2.substring(1, 9), 16);
- int offs = Integer.parseInt(line2.substring(10, 14), 16);
- byte[] temp = new byte[2048];
- byte[] data = new byte[WIDTH2 * HEIGHT];
- int[] idxs = new int[WIDTH2 * HEIGHT];
- for (int i=0; i<HEIGHT; i++) {
- idxs[i * WIDTH2] = (HEIGHT - 1 - i) * WIDTH2;
- for (int j=1; j<WIDTH2; j++)
- idxs[i * WIDTH2 + j] = idxs[i * WIDTH2 + j - 1] + 1;
- }
- int idx = 0;
- int didx = 0;
- while (((line = reader.readLine()) != null)) {
- if(line.startsWith("block")) {
- block = Integer.parseInt(line.substring(6, 11), 16);
- idx = 0;
- }
- if(line.startsWith("0")) {
- for(int i=0; i<16; i++) {
- int a = CHARS.indexOf(line.charAt(5+3*i));
- int b = CHARS.indexOf(line.charAt(6+3*i));
- temp[idx++] = (byte) (a << 4 | b);
- }
- }
- if (idx == 2048) {
- if(block < block2) continue;
- int start = offs;
- if(didx != 0) start = 0;
- for(int i=0; i<2048; i++) {
- if(i >= start)
- data[idxs[didx++]] = temp[i];
- if(didx == WIDTH2 * HEIGHT) {
- System.out.println(toHex(block2)+"."+toHex(offs));
- out = new BufferedOutputStream(new FileOutputStream("pic/"+toHex(block2)+toHex(offs)+".bmp"));
- out.write(filehead);
- out.write(infohead);
- out.write(data);
- out.flush();
- out.close();
- line2 = reader2.readLine();
- if(line2 == null || line2.equals("")) {
- reader.close();
- reader2.close();
- return;
- }
- block2 = Integer.parseInt(line2.substring(1, 9), 16);
- offs = Integer.parseInt(line2.substring(10, 14), 16);
- didx = 0;
- }
- }
- idx = 0;
- }
- }
- reader.close();
- reader2.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
复制代码
待编辑...
回15楼:
代码有一些要改动的地方, 我完善一下就传附件
另外用英文说明这...{:11_336:}
我先用中文注释一下, 然后再慢慢翻译 |
评分
-
1
查看全部评分
-
|