|
|
发表于 2014-6-2 17:03:11
|
显示全部楼层
本帖最后由 meigen 于 2014-10-10 20:19 编辑
, [4 `. c. D# {, x/ i5 b. u( @8 k+ N5 y
接14楼,单色图的提取稍微麻烦些,他里面只有数据部分而缺少文件头,这个是比较头疼的事情
I7 a+ L9 {; X" s/ ]8 v先用ebdump提取出词典文本(本文),然后在里面获取单色图的代码(<1F44>开头,<1F64>结尾)
6 v5 E+ {; }! W+ ]" |# X可以看到
) j1 G+ B6 }# X# M) o<1F44><0001><w=200,h=256>xxx<1F64>[0001A4BD:0027]
9 h$ E. m5 r) U这里的w=200,h=256表示图片的尺寸,这个参数后面会用到' f- M/ N, e. l2 l. E5 d2 O# H7 |
然后<1F64>后面的这一段[0001A4BD:0027]就是单色图数据地址了
" c5 R/ U, Q! W- X! u' f6 ~先写个Demo 把所有地址都提取出来,顺便排一下序,去掉重复:
$ c' C4 m. b: r3 f1 j# o. x- static void getMonoTag(String f) {/ G: S% F; M6 j. |( l* D% a0 q
- try {
7 N( t' j8 C5 R y1 h - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));& i- f; [+ M. M% [% \% e# n+ a9 |7 H( [
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f+".mono.txt"), "UTF-8"));
5 i% D$ p. D5 X3 ]! b; c - String line;" j" |5 q) N( s4 x% D0 f
- ArrayList<String> monos = new ArrayList<String>();
" N5 F/ f9 k5 ]- ^' U4 f# t - while (((line = reader.readLine()) != null)) {
! k$ A) a" e: E2 J - while (line.contains("<1F64>")) {
$ s! W- L1 k6 v; ~# n - line = line.substring(line.indexOf("<1F64>") + 6);5 w8 |% B6 g; p x4 K: D
- monos.add(line.substring(0, 15));3 U% E& ~5 N5 \+ k! O9 ]! o
- }
: q) f& O, ]# C) |/ h% ` - }, x; K4 x$ ?+ @, r$ g/ a( d" J
- reader.close();
- L: }1 J8 e0 _4 Z! N6 @; V. B, D' e - String[] monoa = new String[monos.size()];2 F* E) \- i$ r7 ^+ N( S
- monos.toArray(monoa);: V o M; ?5 \) K' u: @
- Arrays.sort(monoa);
) h, W+ e! C8 c, N8 D - String last = "";
& O0 L+ ?4 E% y - for (int i=0; i<monoa.length; i++) {) Z+ M9 H& p( W' g* I, T. z! d
- if (!monoa[i].equals(last))
, Y. Z0 S* d8 x. g' @: L - writer.write(monoa[i] + "\r\n");( E' I2 w l. a, ^# `
- last = monoa[i];( F8 l& A/ A6 a: i# L3 m3 b
- }
( v, i6 l! w7 l& u! _0 e - writer.close();: A$ t0 o6 l& w9 L1 I3 @$ y
- } catch (Exception e) {' e% s. x3 i( L/ ^4 ], m; E
- e.printStackTrace();
5 _! Q0 q9 {* [2 L+ G6 A& s/ | - }
* R, f2 B( h7 l L' r8 L - }
复制代码 # L! g2 w1 a8 }0 h0 P; {
得到了一个.mono.txt的文件
0 A2 Y6 R' k8 U5 |- K, W然后开始提取:
. i* I% A: a& H上面有提到w=200,h=256这两个参数,不过epwing好像弄反了,200是高,256是宽。 - -2 s- d4 V' B$ o! T7 Q# `
提取过程中需要手动加上图像的文件头,可自行百度bmp文件格式1 k S& H; }& }: ]
- static final int WIDTH = 256;
% r* `8 v! c- h' d0 | - static final int HEIGHT = 200;+ p# y x7 p8 P6 F
- static final int WIDTH2 = 32;
' Y4 }/ n1 g" Z - static final int SIZE = WIDTH2 * HEIGHT;6 z) i' w' z+ Y$ v8 {: e
- static final int FILE_LEN = SIZE + 62;
3 O/ I& }' u( i; ^4 Y - static byte[] filehead = {0x42, 0x4d,
4 h8 w) z# I3 P - (byte) (FILE_LEN & 0xff), (byte) ((FILE_LEN >> 8) & 0xff), (byte) ((FILE_LEN >> 16) & 0xff), (byte) ((FILE_LEN >> 24) & 0xff),1 [, V6 h' L0 f! ^$ }
- 0, 0, 0, 0, 0x3e, 0, 0, 0};
/ Y4 E9 K6 M; }: a* y' x - static byte[] infohead = {0x28, 0, 0, 0,
: |1 O. B9 L9 J/ p- D; ?2 Z" f$ C - (byte) (WIDTH & 0xff), (byte) ((WIDTH >> 8) & 0xff), (byte) ((WIDTH >> 16) & 0xff), (byte) ((WIDTH >> 24) & 0xff),0 a$ _7 N. v' [* a o7 X
- (byte) (HEIGHT & 0xff), (byte) ((HEIGHT >> 8) & 0xff), (byte) ((HEIGHT >> 16) & 0xff), (byte) ((HEIGHT >> 24) & 0xff),8 X @6 V4 C$ d. h$ w
- 1, 0, 1, 0, 0, 0, 0, 0,
. g; m' _3 d- Y9 ^. { - (byte) (SIZE & 0xff), (byte) ((SIZE >> 8) & 0xff), (byte) ((SIZE >> 16) & 0xff), (byte) ((SIZE >> 24) & 0xff),' [: G2 w( d2 s+ g
- 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0};' ^: i8 e. W/ @' n
- static void getMonoPic(String f, String m) {7 b2 n+ h- r1 o7 Z1 b+ F
- try {; H5 z0 M; y& ]+ [# E) Y8 Q) E! Y
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));
: m# Y- B" f0 S; X% A; f - BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(m+".txt"), "UTF-8"));/ ]' U& S* O7 T; H' j
- OutputStream out = null;
( }5 H% F: {. C5 ?! E! z - String line = "";
# m; l( k5 N: ?- y' \* T @/ f - String line2 = reader2.readLine();' O; J6 b3 Z5 x5 l5 G: r; L
- int block = 0;' m) D3 j8 d7 J! M2 C
- int block2 = Integer.parseInt(line2.substring(1, 9), 16);" s# Q/ t1 \" ?- m
- int offs = Integer.parseInt(line2.substring(10, 14), 16);7 T7 `, `$ Q" d) \4 i7 W
- byte[] temp = new byte[2048];: @2 \$ Y6 I3 T6 f0 @/ u T
- byte[] data = new byte[WIDTH2 * HEIGHT];: P( Q$ c& P) f; A
- int[] idxs = new int[WIDTH2 * HEIGHT];; i6 M3 H& U, B, K9 r
- for (int i=0; i<HEIGHT; i++) {7 G* p+ Y: R4 T7 G0 N+ Z& b
- idxs[i * WIDTH2] = (HEIGHT - 1 - i) * WIDTH2;
3 N8 ` H' { W4 x% E- e; P - for (int j=1; j<WIDTH2; j++)
3 j* s3 ~/ M$ ] - idxs[i * WIDTH2 + j] = idxs[i * WIDTH2 + j - 1] + 1;
/ N1 I% w! a8 j5 W2 d' } - }
; f2 W8 h1 B0 @' s$ @ - int idx = 0;
8 Q. Z0 T' o4 M1 { W a& [ - int didx = 0;7 G/ W9 f( z( }" E" U7 r
- while (((line = reader.readLine()) != null)) {
* Y8 c9 M0 F4 X! ~ - if(line.startsWith("block")) {
' T5 j* v' U, O3 O - block = Integer.parseInt(line.substring(6, 11), 16);
2 L/ H) r4 C B! a4 Q1 w - idx = 0;- v9 D, F8 A. C3 Z: N3 M7 I
- }5 f% B8 A& [9 q
- if(line.startsWith("0")) {6 l- @! M3 v+ |' z
- for(int i=0; i<16; i++) {
p6 a+ d: h3 W* n - int a = CHARS.indexOf(line.charAt(5+3*i));
R# Z# ?. a. r% K( j6 l - int b = CHARS.indexOf(line.charAt(6+3*i));
* M5 g& q# O. i - temp[idx++] = (byte) (a << 4 | b);% @' I) h$ x/ C G0 n
- }, `0 Q5 ^3 u& }
- }6 @& v+ @# r T& l
- if (idx == 2048) {/ F9 ^; ^ A# F# W- `+ K
- if(block < block2) continue;9 N! t/ s: i' W4 `* k
- int start = offs;
2 S$ n$ p& b4 a1 {! G+ X - if(didx != 0) start = 0;5 W% O1 d, Q: L+ K
- for(int i=0; i<2048; i++) {- N9 I' U+ I5 B! e5 o* ]5 I# J2 N' u
- if(i >= start)! W; R! s# a) A8 v+ _" z
- data[idxs[didx++]] = temp[i];6 f3 G2 t, I: |( r6 {9 t
- if(didx == WIDTH2 * HEIGHT) {4 p, c+ l9 X8 y% S5 c$ J: b6 X I
- System.out.println(toHex(block2)+"."+toHex(offs));
1 l+ O: f5 |# q" j6 y% T% _4 b - out = new BufferedOutputStream(new FileOutputStream("pic/"+toHex(block2)+toHex(offs)+".bmp"));
' r0 V7 W& q: {/ @, z" z4 p - out.write(filehead);, b: D/ B$ F' Q% w
- out.write(infohead);
% } F+ X/ r' b1 U; w* a% t - out.write(data);
2 x! `3 p; l1 l, I1 @ - out.flush();
0 h# G' Q) B+ M# {" J - out.close();
4 e3 }8 f7 s: l& K - line2 = reader2.readLine();
8 H/ E6 `6 X$ i3 I9 Z - if(line2 == null || line2.equals("")) {
# f8 \+ c1 T% |3 p6 e - reader.close();* L5 Y/ m8 k8 J* @1 ?
- reader2.close();
]) m7 ]: m6 [2 ?4 q - return;9 _7 r3 Y( O% I& a
- }
2 n7 ~. e6 c) w - block2 = Integer.parseInt(line2.substring(1, 9), 16);
. S' y- t0 y8 e3 U - offs = Integer.parseInt(line2.substring(10, 14), 16);" t4 W2 `$ f7 U$ }( t" W- m
- didx = 0;
9 @% Q- q) c3 Q7 N* x+ k - }
6 A0 S% O( L! L8 e/ L4 V% b - }
! C' n! G! K5 c% ~ - idx = 0;2 [9 G& S( @( M
- }
' P& J! J# F+ y a7 F5 v1 {. F - }8 Q) |" t; K* U6 G+ q" f
- reader.close();
$ A4 O5 h# N* [4 g5 g- Z3 R5 u - reader2.close();# l5 Y- }* z$ |8 j
- } catch (Exception e) {
3 t+ G5 I# m9 R2 e) z* J. [1 F1 i& A - e.printStackTrace();
3 h: e( T: ~4 x, q, d - }
3 y) w/ `/ U4 h1 x" _5 O' H' s0 \ - }
复制代码
% C4 u2 i! @, u8 O4 g% o' J9 }9 e待编辑...
. x$ N0 O% r: J0 \/ B5 C& ]) M) f0 e5 p. h! E4 j" X
回15楼:
( T8 H( {) X/ _& R, \9 O0 n. ]; ?4 A d" m( D
代码有一些要改动的地方, 我完善一下就传附件; d) E1 x4 v& F3 d+ o4 {
另外用英文说明这...{:11_336:} 9 c9 m K1 ]/ l
我先用中文注释一下, 然后再慢慢翻译 |
评分
-
1
查看全部评分
-
|