Displaying blob image extracted from SQLitye DB at TAdvStringGrid
Posted: 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.?
The methods mentioned in manual to display image are as follows
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
While this dont work , gives SQLException error.
Anypone has idea how to LoadFromStream data at TPicture ? or how it can be done?
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;
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;
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;
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;