Delphi 從網路抓取圖片顯示於TBrowser在Android/OSX/iOS/Win的最佳方式

解法很簡單,就是在WebBrowser中設定一個寬與高都100%的圖片
[pascal]
const
cHtmlString = ‘<img src=%s width=100% height=100%>’;
var
UrlOfImage: string;
begin
UrlOfImage := ‘http://www.xxxx.xxx/xxx.jpg’;
WebBrowser1.LoadFromStrings(Format(cHtmlString, [UrlOfImage]), ”);
end;
[/pascal]

Delphi將Image存入MySQL資料庫

存入
[php]
var astream : Tmemorystream;
begin
AStream := TMemoryStream.Create;
try
Image1.Picture.Graphic.SaveToStream(AStream);
AStream.Position := 0;
if adoquery1.Active then
begin
adoquery1.Edit;
TBlobField(adoquery1.FieldByName(‘File’)).LoadFromStream(AStream);
adoquery1.Post;
end;
finally
AStream.Free;
end;
[/php]

取出
[php]
var
Ms:TStringStream;
jpg1:Tjpegimage;
begin
Ms := TStringStream.Create(”);
jpg1 := Tjpegimage.create;
try
if adoquery1.Active then
begin
TBlobField(adoquery1.FieldByName(‘File’)).SaveToStream(Ms);
Ms.Position := 0;
jpg1.LoadFromStream(ms);
image1.Picture.Bitmap.Assign(jpg1);
end;
finally
ms.Free;
jpg1.Free;
end;
[/php]

注意,如果出現Got a packet bigger than ‘max_allowed_packet’ bytes
在My.ini加上
max_allowed_packet = 10M