幫忙看看圖像轉化為字符串的問題!NeutronDelphi請進! (50分)

  • 主题发起人 主题发起人 shiyu281
  • 开始时间 开始时间
S

shiyu281

Unregistered / Unconfirmed
GUEST, unregistred user!
BMP轉成字符串
function BmpToString(Bmp: TBitmap): string;
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string;
begin
BinStream := TMemoryStream.Create;
try
StrStream := TStringStream.Create(s);
try
Bmp.SaveToStream(BinStream);
BinStream.Seek(0, soFromBeginning);
ObjectBinaryToText(BinStream, StrStream);
//執行到(ObjectBinaryToText(BinStream, StrStream))會出錯:"INvalid stream format",不知什么原因?
StrStream.Seek(0, soFromBeginning);
Result:= StrStream.DataString;
finally
StrStream.Free;
end;
finally
BinStream.Free
end;
end;
字符串轉成BMP

function StringToBmp(Value: string): TBitmap;
var
StrStream:TStringStream;
BinStream: TMemoryStream;
begin
StrStream := TStringStream.Create(Value);
try
BinStream := TMemoryStream.Create;
try
ObjectTextToBinary(StrStream, BinStream);
BinStream.Seek(0, soFromBeginning);
Result.LoadFromStream(BinStream);
finally
BinStream.Free;
end;
finally
StrStream.Free;
end;
end;

我想把圖片轉為字符串後存入數據庫,顯示時再轉為BMP
請問:是不是這樣寫?

procedure TForm1.Button1Click(Sender: TObject);
var
MYBMP:TBitmap;
begin
MYBMP:=TBitmap.Create ;
MyBmp.LoadFromFile('E:/Tool/EP/新資料夾/E7430.bmp');

ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from IUPT');
ADOQuery1.Open ;
ADOQuery1.Append ;
ADOQuery1['UPT']:=BmpToString(MYBMP); //UPT 數據庫格式 Varchar(100)
TBlobField(ADOQuery1.FieldbyName('UPT')).LoadFromStream(BmpToString(MYBMP);
因為Function出問題,所以不知道上面兩種存法,哪一個對?或者是其它方法?

ADOQuery1.post;

MYBMP.Free;
end;
 
ObjectBinaryToText 是用来转换Component的,你说的把图像转换为字符串是什么意思?

Come From Help :

ObjectBinaryToText procedure
-------------------------------
Converts the binary representation of an object into more readily
understandable text.
 
后退
顶部