Einzelnen Beitrag anzeigen

Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#20

Re: Bild als String übertragen?

  Alt 12. Dez 2008, 18:36
Och manno....

Delphi-Quellcode:
var
  strBitmap: string;

function BitmapToString(InputBmp: TBitmap; var outString: String): BOOL;
var
  ms: TMemoryStream;
begin
  Result := FALSE;
  outString := '';

  ms := TMemoryStream.Create;
  try
    ms.Position := 0;
    InputBmp.SaveToStream(ms);
    SetString(outString, PChar(ms.Memory), ms.Size);

    Result := TRUE;
  finally
    ms.Free;
  end;
end;

function BitmapFromString(OutputBmp: TBitmap; inString: String): BOOL;
var
  ms: TMemoryStream;
begin
  Result := FALSE;

  ms := TMemoryStream.Create;
  try
    ms.Position := 0;
    ms.WriteBuffer(inString[1], length(inString));
    ms.Position := 0;

    OutputBmp.LoadFromStream(ms);
    inString := '';

    Result := TRUE;
  finally
    ms.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  BitmapToString(Image1.Picture.Bitmap, strBitmap);

  BitmapFromString(Image2.Picture.Bitmap, strBitmap);
  Self.Invalidate;
end;
Angehängte Dateien
Dateityp: zip simplesample_202.zip (246,0 KB, 12x aufgerufen)
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat