Chip123 科技應用創新平台
標題:
關於BMP轉logo
[打印本頁]
作者:
Butler99
時間:
2021-5-7 10:16 AM
標題:
關於BMP轉logo
請問大家layout logo是怎麽做得,感覺BMP 單色位轉成layout效果不好,如果采用這個方法要每個字母做成一個cell,然後還要load一個可以自動縮放的script,而且轉成單色位圖片會有很嚴重的毛邊,轉出來會很難看,所以是怎麽做比較好
4 w5 e$ B$ P5 F0 i4 D
3 D+ _# P/ N+ Z$ b( y2 g
以下是skill
" O8 e; w3 ~- j- T
let((win cv bmpfile bmpSize WORD Wnum number Grid Layer row column max_column
* D X; Z7 O# w5 R: ?, q8 z. ^
i dot x y signature offset width height pixel ImageSize )
/ R% l1 z5 R& C* j, `' [3 a
& E4 {) K/ e) U* d/ J
win = hiGetCurrentWindow()
3 @4 k8 }- r' p0 D" }) v' U- \+ f# A
cv = getEditRep(win)
( ]' j" k+ b' e0 v$ U" H' q, U ~
3 c: P+ j2 W8 y5 {' V
bmpfile = "~/number_mini.bmp" ;;; Input BMP File
& { j3 ~4 l& B$ J6 s+ j
Layer = list("TTOPME" "drawing") ;;; Output Layer
% V5 P* }6 m( n2 B3 h7 Z: D# m1 e
Grid = 1 ;;; Rectangle Size
" t o* q6 m% P
column = 0
8 @5 U, q8 a o0 P+ a7 {
+ d' f& v! q6 p% P, h ^$ [6 ~
procedure(MessageForm(text)
# N" W/ W3 {5 e$ Y
prog( ()
# c- D5 b: M) e, ^8 f9 V
hiDisplayAppDBox(
I2 b4 e6 ~# {, Y& P) v
?name 'JWDBox_Message
$ @& w/ ?( F6 L8 a1 X7 X8 @5 l
?dboxBanner "Message!!"
4 c/ Z- h M i! K+ }2 D5 k
?buttonLayout 'Close
' c7 U, @( ]7 E2 w2 g& }
?dboxText text
, i! b, h' E/ ]8 @% d: u& p
)
) Y) d1 B4 S( ?+ |
);prog
6 r9 c v {+ f4 u
);procedure
a* v1 ^. q9 p0 p T
" F% K4 A6 T, B: \6 k$ Z7 [4 Y$ t1 I
;Read BMP file
9 }) _3 g: K. l$ h6 B
if(InFile = infile(bmpfile) then
$ m3 H: K5 q- S+ [9 j1 m# H2 H" J
bmpSize = fileLength(bmpfile)
* W2 [6 G# N [) {% w7 A# E
declare(WORD[bmpSize])
+ v) |( p+ ^3 p& m) \
for(Wnum 0 bmpSize-1 WORD[Wnum] = charToInt(getc(InFile)) )
, _. _0 `& K7 E# g' p* M
close(InFile)
' F+ D+ |' y }& _& V
else
2 ?& g8 L$ h3 Z% z
MessageForm("Input file does not exist!")
4 a& |/ u0 d- b0 c1 D7 O7 j
return()
4 x2 R& O/ A: y8 J6 l9 c
)
7 q/ m$ a4 h+ }8 Q
7 Y3 C' Q: u. ]9 z+ F. H
sprintf(signature "%02x%02x" WORD[0] WORD[1])
, U2 y7 k* _3 m8 E) P z
offset = (WORD[0x0d]<<24) + (WORD[0x0c]<<16) + (WORD[0x0b]<<8) + WORD[0x0a]
6 v% K, y. K4 V1 }( E
width = (WORD[0x15]<<24) + (WORD[0x14]<<16) + (WORD[0x13]<<8) + WORD[0x12]
* I$ W5 K7 J; y: z
height = (WORD[0x19]<<24) + (WORD[0x18]<<16) + (WORD[0x17]<<8) + WORD[0x16]
# i! R3 X3 U8 `) ?
pixel = (WORD[0x1d]<<8) + WORD[0x1c]
, I6 }, H n& e* d& v$ l
ImageSize = (WORD[0x25]<<24) + (WORD[0x24]<<16) + (WORD[0x23]<<8) + WORD[0x22]
/ `1 o' d: f- H3 T0 g4 r
1 V: E7 u8 y, k# V
printf("--- BMP2LAY Start --- %L\n" getCurrentTime())
& P3 h4 z# {1 j# P7 `0 W
printf("offset : 0x%x \n" offset)
; `: s+ D5 R/ C0 X: R3 v
printf("width : 0x%x \n" width)
: q+ X- W3 Z$ [4 ?5 e. n& S
printf("height : 0x%x \n" height)
0 E3 [! |5 Q7 M1 y4 ^
printf("ImgSize : 0x%x \n" ImageSize)
0 E# Z; T( d5 N9 R" i, Q2 B
' ?: R$ N) a8 j( J! F
;check bmp file
- @) L7 `) o8 [
if(!equal(signature "424d") then
! K0 |& S, m" r+ ~
MessageForm("*ERROR* Standard Input is not a BMP file")
0 f3 i6 h. i7 m2 ?2 J8 `
return()
' d6 _3 N4 Z% @
)
0 U) V* r ?2 `
0 W& c8 u# ?1 s w* ~. x
;check mono bmp file
9 U3 E9 l4 }# q4 y# R1 Y% T1 o5 U1 [
if(!equal(pixel 0x01) then
+ C2 a+ l- z5 K0 S
MessageForm("*ERROR* only supports mono bmp files")
/ [& Z2 z7 Z& ?- x$ |% w. b i
return()
- ]. z4 y1 P( r2 @/ H, W2 }$ J( G
)
4 _- W7 l0 e; N9 S2 Y
J0 o" w- S! E& r7 [$ s# D
;BMP2LAY
+ A' V7 H, @1 r/ \; ]- |
max_column = ImageSize/height<<3
% P' c; B2 R/ R* [, a2 ]; e
number = offset+ImageSize-1
. T. z# ?1 A X# Z/ ^$ Y" j% B
8 G5 I6 R: J8 C! ]
for(Wnum offset number
! ~+ J& Z. m1 g5 V8 l. D6 u
row = fix((Wnum-offset)/(max_column>>3))
# U# {" `, K' f3 P& e
y = Grid*row
3 O2 I! Z6 D( R3 E8 R6 p
2 y# v2 e4 m) f7 |1 _" q7 u
for(i 0 7
) `' Z. d5 t* I* v) d( O
dot = bitfield1(WORD[Wnum] 7-i) ; bit<7> ~ bit<0>
1 D; Q2 d, j* o2 m0 g5 M$ y# f
x = Grid*column
! R M% R# S, {+ ]' a, u2 @
if(zerop(dot) && column<width then
2 E2 O+ T" q/ w- x
geSelectObject(dbCreateRect(cv Layer list(x:y x+Grid:y+Grid)))
' m) B) S! q# ] L) N j
)
9 l: O( Q4 s% H2 `* G! s8 x4 i3 S
column++
7 w h' |6 w Z" J6 H8 y% h
);for
$ y- L5 {7 g6 M% j* Z
if(equal(column max_column) column=0)
' I) q* g. i/ ~# Y/ w9 g6 ^
Wnum++
7 r) A; Q* c# |# C1 s ?
);for
" y3 j$ l" ]' s- @1 E# }: I6 H
! h- G) O$ ?0 `5 x3 A" a9 D
hiZoomIn(win list(-10:-10 x+10:y+10))
/ V9 g! F; H9 w6 {& q% G1 y
printf("--- BMP2LAY End ----- %L\nt\n" getCurrentTime())
$ L6 V# M" R& B* ~9 r4 f9 _& X# |* n
);let
0 c7 K# X2 A4 W& ^3 n. p
% k! y& h; ?% j( b2 g+ |$ I0 ]
歡迎光臨 Chip123 科技應用創新平台 (http://chip123.com/)
Powered by Discuz! X3.2