Displaying blob image extracted from SQLitye DB at TAdvStringGrid

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ninadbe
Posts: 2
Joined: Fri 06 Sep 2013 16:28

Displaying blob image extracted from SQLitye DB at TAdvStringGrid

Post by ninadbe » Fri 06 Sep 2013 16:48

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 dataset to display results at TAdvSTringGRid (code is given below).
All other values are displaying perfectly except Image in database. Where it is expected to show image, it is showing junk characters.

How to display image perfectly from DataBase at TAdvStringGrid.?

Code: Select all

while not results.EOF do
begin
if (j>sg.rowcount) then
sg.rowcount := sg.rowcount + 1;
for i := 0 to results.fields.Count - 1 do
begin
if i=0 then

else if i = 4 then
//Here I want to display image from db
else
sg.cells[i,j] := results.FieldByName(names[i]).AsString;
end;
results.Next;
inc(j);
end;  
The methods mentioned in manual to display image are as follows

Code: Select all

Grid.CreatePicture(2,3,True,Shrink,0,haLeft,vaTop).LoadFromFile(‘TST.JPG’);
procedure AddPicture(ACol,ARow: Integer;APicture:TPicture;transparent: Boolean; stretchmode:TStretchMode; padding: Integer; hal:TCellHalign; val:TCellValign);
function GetPicture(ACol,ARow: Integer): TPicture;
Grid.CreateFilePicture(2,3,True,Shrink,0,haLeft,vaTop).Filename := ‘TST.JPG’;  

Code: Select all

function CreatePicture(ACol,ARow:Integer; transparent:Boolean; stretchmode:TStretchMode; padding:Integer; hal:TCellHalign; val:TCellValign):TPicture; 


function AddPicture(ACol,ARow:Integer; aPicture:TPicture; transparent:Boolean; stretchmode:TStretchMode; padding:Integer; hal:TCellHalign; val:TCellValign):TPicture; 
But it is not given there how to display it with dataset.

When used with static image from file the code works well problem only with TStram & TPicture while working with DataSet. DataSet is extracting image in junk characters format as it is BLOB type.

This works well

Code: Select all

            try
               Picture.LoadFromFile('C:\dattaguru.png');
               sg.AddPicture(i,j,Picture,True,ShrinkWithAspectRatio,0,haLeft,vaTop);
           finally
               Stream1.Free;
While this dont work , gives SQLException error.

Code: Select all

            try
               Field := TBlobField(results.FieldByName(names[i]).AsString);
               Stream := results.CreateBlobStream(Field, bmReadWrite);
               Picture.Graphic.LoadFromStream(Stream1);
               sg.AddPicture(i,j,Picture,True,ShrinkWithAspectRatio,0,haLeft,vaTop);
           finally
               Stream1.Free;
Anypone has idea how to LoadFromStream data at TPicture ? or how it can be done?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Displaying blob image extracted from SQLitye DB at TAdvStringGrid

Post by AlexP » Mon 09 Sep 2013 09:22

Hello,

To load data from a BLOB field to Stream, you needn't to map the field to string, You can directly save data to Stream in the following way:

Code: Select all

TBlobField(results.FieldByName(names[i]).SaveToStream(Stream1);

Post Reply