Hi,
I have created a class for a bluetooth Fingerprint scanner and I managed to get working most of the function without many problems.
However, there is a function which allows me to retrieve a image from the sensor, which I would like to try.
From the reader I get an array of bytes, which are the image data (no headers or any other information). From documentation I understand that this is suposed to be translated to a black & white BMP.
So I have the array of bytes. Does any one knows how to transform and save them as BMP ?
I have tryed to convert this Java code to B4A, either by creating B4A code or using inline Java without success...Allways get a bad image file.
I think I'm close..but I'm not getting there.
Some clue will be very helpfull.
Many thanks
I have created a class for a bluetooth Fingerprint scanner and I managed to get working most of the function without many problems.
However, there is a function which allows me to retrieve a image from the sensor, which I would like to try.
From the reader I get an array of bytes, which are the image data (no headers or any other information). From documentation I understand that this is suposed to be translated to a black & white BMP.
So I have the array of bytes. Does any one knows how to transform and save them as BMP ?
I have tryed to convert this Java code to B4A, either by creating B4A code or using inline Java without success...Allways get a bad image file.
I think I'm close..but I'm not getting there.
Some clue will be very helpfull.
Many thanks
B4X:
private byte[] changeByte(int data) {
byte b4 = (byte) ((data) >> 24);
byte b3 = (byte) (((data) << 8) >> 24);
byte b2 = (byte) (((data) << 16) >> 24);
byte b1 = (byte) (((data) << 24) >> 24);
byte[] bytes = { b1, b2, b3, b4 };
return bytes;
}
private byte[] toBmpByte(int width, int height, byte[] data) {
byte[] buffer = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
int bfType = 0x424d;
int bfSize = 54 + 1024 + width * height;
int bfReserved1 = 0;
int bfReserved2 = 0;
int bfOffBits = 54 + 1024;
dos.writeShort(bfType);
dos.write(changeByte(bfSize), 0, 4);
dos.write(changeByte(bfReserved1), 0, 2);
dos.write(changeByte(bfReserved2), 0, 2);
dos.write(changeByte(bfOffBits), 0, 4);
int biSize = 40;
int biWidth = width;
int biHeight = height;
int biPlanes = 1;
int biBitcount = 8;
int biCompression = 0;
int biSizeImage = width * height;
int biXPelsPerMeter = 0;
int biYPelsPerMeter = 0;
int biClrUsed = 256;
int biClrImportant = 0;
dos.write(changeByte(biSize), 0, 4);
dos.write(changeByte(biWidth), 0, 4);
dos.write(changeByte(biHeight), 0, 4);
dos.write(changeByte(biPlanes), 0, 2);
dos.write(changeByte(biBitcount), 0, 2);
dos.write(changeByte(biCompression), 0, 4);
dos.write(changeByte(biSizeImage), 0, 4);
dos.write(changeByte(biXPelsPerMeter), 0, 4);
dos.write(changeByte(biYPelsPerMeter), 0, 4);
dos.write(changeByte(biClrUsed), 0, 4);
dos.write(changeByte(biClrImportant), 0, 4);
byte[] palatte = new byte[1024];
for (int i = 0; i < 256; i++) {
palatte[i * 4] = (byte) i;
palatte[i * 4 + 1] = (byte) i;
palatte[i * 4 + 2] = (byte) i;
palatte[i * 4 + 3] = 0;
}
dos.write(palatte);
dos.write(data);
dos.flush();
buffer = baos.toByteArray();
dos.close();
baos.close();
} catch (Exception e) {
e.printStackTrace();
}
return buffer;
}