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;
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;