0
I need to convert to Pascal / Firemonkey the java code below:
the main doubts are:
how to extract each pixel in firemonkey?
how this code operates:
slice |= (byte) ((v ? 1 : 0) << (7 -b));
Follow the full 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);
}
See if it helps http://stackoverflow.com/questions/tagged/firemonkey
– KingRider