I need to convert the following java code to Pascal / Firemonkey:
The main questions are:
-
How to extract each pixel in firemonkey?
-
How does this code work:
slice |= (byte) ((v ? 1 : 0) << (7 -b));
Follow the complete code:
public static boolean ImageToEsc(Bitmap im, OutputStream out, int bytes, Integer density)
{
try
{
int wid = im.getWidth();
int hei = im.getHeight();
byte[] blen = new byte[2];
int [] dots = new int[wid * hei];
im.getPixels(dots, 0, wid, 0, 0, wid, hei);
blen[0] = (byte) (wid / 8);
blen[1] = (byte) bytes;
int offset = 0;
while (offset < hei)
{
for (int x = 0; x < wid; ++x)
{
for (int k = 0; k < bytes; ++k)
{
byte slice = 0;
for (int b = 0; b < 8; ++b)
{
int y = (((offset / 8) + k) * 8) + b;
int i = (y * wid) + x;
boolean v = false;
if (i < dots.length) {
v = (dots[i]==Color.BLACK);
}
slice |= (byte) ((v ? 1 : 0) << (7 -b));
}
out.write(slice);
}
}
offset += (bytes * 8);
}