Here is a small example how you can change your method for the conversion from BitMatrix to Bitmap. The method does the scaling of the BitMatrix.
int BLACK = 0xFF000000;
int WHITE = 0xFFFFFFFF;
// change the values to your needs
int requestedWidth = 300;
int requestedHeight = 300;
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
// calculating the scaling factor
int pixelsize = requestedWidth/width;
if (pixelsize > requestedHeight/height)
{
pixelsize = requestedHeight/height;
}
int[] pixels = new int[requestedWidth * requestedHeight];
// All are 0, or black, by default
for (int y = 0; y < height; y++) {
int offset = y * requestedWidth * pixelsize;
// scaling pixel height
for (int pixelsizeHeight = 0; pixelsizeHeight < pixelsize; pixelsizeHeight++, offset+=requestedWidth) {
for (int x = 0; x < width; x++) {
int color = bitMatrix.get(x, y) ? BLACK : WHITE;
// scaling pixel width
for (int pixelsizeWidth = 0; pixelsizeWidth < pixelsize; pixelsizeWidth++) {
pixels[offset + x * pixelsize + pixelsizeWidth] = color;
}
}
}
}
Bitmap bitmap = Bitmap.createBitmap(requestedWidth, requestedHeight, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, requestedWidth, 0, 0, requestedWidth, requestedHeight);
// I could only test it with BufferedImage and a modified version of the zxing J2SE client
// BufferedImage bitmap = new BufferedImage(requestedWidth, requestedHeight, BufferedImage.TYPE_INT_ARGB);
// bitmap.getRaster().setDataElements(0, 0, requestedWidth, requestedHeight, pixels);