It should be a char type that supports at least 3 bytes, at least for those characters I selected.
I know, LineEnding is different in each OS, I think I was testing it just with chars and never came up it will work in first time
Sure it can be changed easily getting the lenght of LineEnding const and that's all. I must change the
output[i + 1] := #13;
output[i + 2] := #10;
with the corresponding Move(...) to fill always the correct one, and in the size calculation of course.
About using unicode characters, tested under windows and it works fine as is.
Edit: Here it is again. Thanks for your help (both)
function TForm1.Convertir: string;
var
x, y, i: integer;
p: PBGRAPixel;
pix: string;
output: string;
Bitmap: TBGRABitmap;
begin
Bitmap := TBGRABitmap.Create(TheImage);
BGRAReplace(Bitmap, Bitmap.Resample(100, 50, rmSimpleStretch));
// width * 3 (char length) + (lineEnding) * height
SetLength(output, (300 + Length(LineEnding)) * 50);
// fill with whitespace to prevent garbage
FillChar(output[1], Length(output), ' ');
Bitmap.InplaceGrayscale;
i := 1;
for y := 0 to Bitmap.Height - 1 do
begin
p := Bitmap.Scanline[y];
for x := 0 to Bitmap.Width - 1 do
begin
case p^.red of
0..63: pix := '█';
64..127: pix := '▓';
128..191: pix := '▒';
192..254: pix := '░';
255: pix := ' ';
end;
Move(pix[1], output[i], Length(pix));
Inc(i, Length(pix));
if x = Bitmap.Width - 1 then
begin
Move(LineEnding[1], output[i], Length(LineEnding));
Inc(i, Length(LineEnding));
end;
Inc(p);
end;
end;
// Fill whitespace with #0
FillChar(output[i], Length(output) - i, #0);
Bitmap.InvalidateBitmap;
Bitmap.Free;
Result := output;
end;