@@ -49,31 +49,35 @@ object ImageUtils {
49
49
}
50
50
51
51
val bmpHexList = binaryListToHexStringList(list)
52
- val commandHexString = " 1D763000"
53
- var widthHexString = Integer
54
- .toHexString(if (bmpWidth % 8 == 0 )
55
- bmpWidth / 8
56
- else
57
- bmpWidth / 8 + 1 )
58
- if (widthHexString.length > 2 ) {
52
+ val commandHexString = " 1D763000"
53
+
54
+ val printWidth = if (bmpWidth % 8 == 0 ) bmpWidth / 8 else bmpWidth / 8 + 1
55
+ var printLowWidthHex = Integer .toHexString(getLowValue(printWidth))
56
+ var printHighWidthHex = Integer .toHexString(getHighValue(printWidth))
57
+ if (printHighWidthHex.length > 2 ) {
59
58
Log .e(" decodeBitmap error" , " width is too large" )
60
59
return null
61
- } else if (widthHexString.length == 1 ) {
62
- widthHexString = " 0$widthHexString "
60
+ } else if (printHighWidthHex.length == 1 ) {
61
+ printHighWidthHex = " 0$printHighWidthHex "
62
+ }
63
+ if (printLowWidthHex.length == 1 ) {
64
+ printLowWidthHex = " 0$printLowWidthHex "
63
65
}
64
- widthHexString + = " 00"
65
66
66
- var heightHexString = Integer .toHexString(bmpHeight)
67
- if (heightHexString.length > 2 ) {
67
+ var printLowHeightHex = Integer .toHexString(getLowValue(bmpHeight))
68
+ var printHighHeightHex = Integer .toHexString(getHighValue(bmpHeight))
69
+ if (printHighHeightHex.length > 2 ) {
68
70
Log .e(" decodeBitmap error" , " height is too large" )
69
71
return null
70
- } else if (heightHexString.length == 1 ) {
71
- heightHexString = " 0$heightHexString "
72
+ } else if (printHighHeightHex.length == 1 ) {
73
+ printHighHeightHex = " 0$printHighHeightHex "
74
+ }
75
+ if (printLowHeightHex.length == 1 ) {
76
+ printLowHeightHex = " 0$printLowHeightHex "
72
77
}
73
- heightHexString + = " 00"
74
78
75
79
val commandList = ArrayList <String >()
76
- commandList.add(commandHexString + widthHexString + heightHexString )
80
+ commandList.add(commandHexString + printLowWidthHex + printHighWidthHex + printLowHeightHex + printHighHeightHex )
77
81
commandList.addAll(bmpHexList)
78
82
79
83
return hexList2Byte(commandList)
@@ -156,4 +160,22 @@ object ImageUtils {
156
160
return " 0123456789ABCDEF" .indexOf(c).toByte()
157
161
}
158
162
159
- }
163
+ private fun getLowValue (rawValue : Int ): Int {
164
+ var value = rawValue
165
+ while (value > 255 ) {
166
+ value - = 256
167
+ }
168
+ return value
169
+ }
170
+
171
+ private fun getHighValue (rawValue : Int ): Int {
172
+ var value = rawValue
173
+ var res = 0
174
+ while (value > 255 ) {
175
+ value - = 256
176
+ res++
177
+ }
178
+ return res
179
+ }
180
+
181
+ }
0 commit comments