How to display BLOB Image from database in the TAdvStringGrid with the help of DataSet

前端 未结 2 419
独厮守ぢ
独厮守ぢ 2020-12-18 13:32

I have been making an application at Delphi XE3. I am trying to display values from database to the TAdvStringGrid component placed on the form. I am using data

2条回答
  •  -上瘾入骨i
    2020-12-18 13:59

    I realize this is a tad late, but I wanted to contribute. I quite simply did the following, having not to worry about the image format (.jpg, .png etc.). I simply create a TStream object, load the BLOB stream into it, and then I load the Image from the stream. Short and sweet, and it works great for me.

       var
         Stream : TStream;
       begin
         try
           Stream := TStream.Create;
           Stream := Dataset.CreateBlobStream(Dataset.FieldByName('SIGNATURE'), bmRead);
           Stream.Position := 0;
           lblPicSize.Caption := 'Picture is ' + IntToStr(Stream.Size) + ' Bytes';
           if Stream.Size <= 0 then
             pnlPic.Caption := ''
           else
             pnlPic.Caption := '';
    
           try
             imgSignature.Picture.LoadFromStream(Stream);
           except
             on E:Exception do
               begin
                 ShowMessage(E.Message);
               end;
           end;
    
     finally
       Stream.Free;
     end;
    end;
    

提交回复
热议问题