|
3 | 3 | import android.annotation.SuppressLint; |
4 | 4 | import android.graphics.Bitmap; |
5 | 5 |
|
6 | | -import com.google.zxing.BarcodeFormat; |
7 | | -import com.google.zxing.EncodeHintType; |
8 | | -import com.google.zxing.WriterException; |
9 | | -import com.google.zxing.common.BitMatrix; |
10 | | -import com.google.zxing.qrcode.QRCodeWriter; |
11 | 6 |
|
12 | 7 | import java.util.Hashtable; |
13 | 8 |
|
@@ -145,63 +140,7 @@ public static byte[] initTable(int h, int w){ |
145 | 140 | return data; |
146 | 141 | } |
147 | 142 |
|
148 | | - /** |
149 | | - * 生成二维码字节流 |
150 | | - * |
151 | | - * @param data |
152 | | - * @param size |
153 | | - * @return |
154 | | - */ |
155 | | - public static byte[] getZXingQRCode(String data, int size) { |
156 | | - try { |
157 | | - Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(); |
158 | | - hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); |
159 | | - //图像数据转换,使用了矩阵转换 |
160 | | - BitMatrix bitMatrix = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, size, size, hints); |
161 | | - //System.out.println("bitmatrix height:" + bitMatrix.getHeight() + " width:" + bitMatrix.getWidth()); |
162 | | - return getBytesFromBitMatrix(bitMatrix); |
163 | | - } catch (WriterException e) { |
164 | | - // TODO Auto-generated catch block |
165 | | - e.printStackTrace(); |
166 | | - } |
167 | | - return null; |
168 | | - } |
169 | 143 |
|
170 | | - public static byte[] getBytesFromBitMatrix(BitMatrix bits) { |
171 | | - if (bits == null) return null; |
172 | | - |
173 | | - int h = bits.getHeight(); |
174 | | - int w = (bits.getWidth() + 7) / 8; |
175 | | - byte[] rv = new byte[h * w + 4]; |
176 | | - |
177 | | - rv[0] = (byte) w;//xL |
178 | | - rv[1] = (byte) (w >> 8);//xH |
179 | | - rv[2] = (byte) h; |
180 | | - rv[3] = (byte) (h >> 8); |
181 | | - |
182 | | - int k = 4; |
183 | | - for (int i = 0; i < h; i++) { |
184 | | - for (int j = 0; j < w; j++) { |
185 | | - for (int n = 0; n < 8; n++) { |
186 | | - byte b = getBitMatrixColor(bits, j * 8 + n, i); |
187 | | - rv[k] += rv[k] + b; |
188 | | - } |
189 | | - k++; |
190 | | - } |
191 | | - } |
192 | | - return rv; |
193 | | - } |
194 | | - |
195 | | - private static byte getBitMatrixColor(BitMatrix bits, int x, int y) { |
196 | | - int width = bits.getWidth(); |
197 | | - int height = bits.getHeight(); |
198 | | - if (x >= width || y >= height || x < 0 || y < 0) return 0; |
199 | | - if (bits.get(x, y)) { |
200 | | - return 1; |
201 | | - } else { |
202 | | - return 0; |
203 | | - } |
204 | | - } |
205 | 144 |
|
206 | 145 | /** |
207 | 146 | * 将bitmap图转换为头四位有宽高的光栅位图 |
|
0 commit comments