Read the image from the database and display

procedure TForm_QTOrder1.ShowPic;
var
  vStr:TADOBlobStream;
  vTmp,vPicType:string;
  vtmpPath:PChar;
begin
  inherited;

  Image1.Picture.Graphic: = nil; // clear the image control in the image
  vstr: = TADOBlobStream.Create (TBlobField (QueryBill4.FieldByName ( 'Pics')), bmRead); // create BlobStream, Pics field is set Blob field and read only
  if vstr.Size = 0 then // Stream size of 0 indicates no image, exit
  the begin
    exit;
  End;
  vPicType: = CheckImgType (VSTR); // determines whether the image type
  vstr.Position: = 0 ; // pointer to the beginning of the
  GetMem (vtmpPath, MAX_PATH); // get a temporary directory
  GetTempPath (MAX_PATH, vtmpPath); // get a temporary directory
  vTmp: = StrPas (vtmpPath); // get a temporary directory
  FreeMem (vtmpPath); / / release variables
  vTmp: = vTmp + PubData1.GetGUIDString + + vPicType; // temporary directory and filename file name and path synthesis '.'
  TBlobField (QueryBill4.FieldByName ( 'Pics')) the SaveToFile (VTMP); // from. save Blob field read image data to a temporary file
  Image1.Picture.LoadFromFile (vTmp); // image control reads the temporary file
  DeleteFile (vTmp); // delete temporary files
  Application.ProcessMessages;
End;

Guess you like

Origin blog.csdn.net/victor_yang/article/details/86217703