Hi
j ai une Function de google mais il ya des problemes !?
//-- TBitmap to String -----------------------
function BmpToTxt(const ABitmap: TBitmap): string;
var X, Y: integer; function ColorToHex(AColor: TColor): string;
begin
Result := IntToHex(GetRValue(AColor), 2 ) +
IntToHex(GetGValue(AColor), 2 ) +
IntToHex(GetBValue(AColor), 2 );
end;
begin
Result := '';
for Y := 0 to ABitmap.Height do
begin
if Y <> 0 then
Result := Result + EL;
for X := 0 to ABitmap.Width do
Result := Result + ColorToHex(ABitmap.Canvas.Pixels[X, Y]);
end;
end;
//-- String to TBitmap -----------------------
functionTxtToBmp(const Text: TStrings): TBitmap;
var X, Y, cy, cx: integer;
sClr: string;
function HexToInt(HexStr: string): integer;
begin
if HexStr = '' then
HexStr := 'FFFFFF';
Result := StrToInt('0x' + HexStr);
end;
function StrToColor(AText: string): TColor;
begin
Result := RGB(HexToInt(Copy(AText, 1, 2)),
HexToInt(Copy(AText, 3, 2)),
HexToInt(Copy(AText, 5, 2)));
end;
begin
X := Length(Text[0]) div 6 - 1;
Y := Text.Count - 1;
Result := TBitmap.Create;
Result.Width := X;
Result.Height := Y;
cy := Y;
cx := X;
for Y := 0 to cy do
begin
for X := 0 to cx do
begin
sClr := Copy(Text[Y], (X * 6) + 1, 6);
Result.Canvas.Pixels[X, Y] := StrToColor(sClr);
end;
end;
end;
And you can use like this:
Memo1.Text := BmpToTxt(Image1.Picture.Bitmap);
Memo1.Lines.SaveToFile('C..Some.txt');
or
Image1.Picture.Bitmap := TxtToBmp(Memo1.Lines);