标签:
TMemoryStream to String
stm: TStream;
ss: TStringStream;
image.picture.savetoStream(stm);
ss := TStringStream.Create(‘‘, TEncoding.Unicode);
ss.CopyFrom(stm, 0);
str := ss.DataString;
stm.Free;
ss.Free;
stm: TStream;
ss: TStringStream;
stm := TMemoryStream.Create;
ss := TStringStream.Create(‘‘, TEncoding.Unicode);
ss.WriteString(str);
ss.Position := 0;
stm.CopyFrom(ss, ss.Size);
stm.Position := 0;
abyte: TBytes;
SetLength(abyte, stm.Size);
stm.Read(abyte, stm.Size);
str := stringof(abyte);
abyte := BytesOf(gstr);
stm.Write(abyte, Length(abyte));
stm.Position := 0;
img.picture.LoadFromStream(stm);
function BytesOf(const Val: UnicodeString): TBytes;
begin
Result := TEncoding.Default.GetBytes(Val);
end;
function StringOf(const Bytes: TBytes): UnicodeString;
begin
if Assigned(Bytes) then
Result := TEncoding.Default.GetString(Bytes, Low(Bytes), High(Bytes) + 1)
else
Result := ‘‘;
end;
标签:
原文地址:http://www.cnblogs.com/cb168/p/4443814.html