Recent

Author Topic: Blob and image importation (SOLVED)  (Read 5963 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2001
    • Lazarus and Free Pascal italian community
Blob and image importation (SOLVED)
« on: November 23, 2010, 02:24:24 pm »
I created a field in a firebird db blob to contain an image. How do I import pictures in it and see how I can make a video preview? Using the TIBConnection to connect to firebird. Thanks
« Last Edit: November 26, 2010, 08:32:53 am by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

leiteiro

  • New Member
  • *
  • Posts: 16
Re: Blob and image importation
« Reply #1 on: November 23, 2010, 07:40:56 pm »
var
    FileStream: TStream;
....
....
....
 
 FileStream := TFileStream.Create(FileName, fmOpenRead);
 imgBlob.Picture.LoadFromStream(FileStream);

xinyiman

  • Hero Member
  • *****
  • Posts: 2001
    • Lazarus and Free Pascal italian community
Re: Blob and image importation
« Reply #2 on: November 24, 2010, 05:52:58 am »
Thank you
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2001
    • Lazarus and Free Pascal italian community
Re: Blob and image importation
« Reply #3 on: November 25, 2010, 02:57:57 pm »
Another question, now that I imported the jpg image in firebird how do I make it display in a TImage field, reading a FieldByName ('namefield')?

Thank you to response
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2001
    • Lazarus and Free Pascal italian community
Re: Blob and image importation
« Reply #4 on: November 26, 2010, 05:57:45 am »
procedure TForm2.Grid_DettaglioGiornoCellClick(Column: TColumn);
var
   MioStream: TStream;
   IdNota: integer;
begin

   IdNota:=Grid_DettaglioGiorno.DataSource.DataSet.FieldByName('IdNota').AsInteger;

   Q_Generica.SQL.Text:='Select Immagine FROM T_Scontrini Where IdNota=' + IntToStr(IdNota) + ';';
   Q_Generica.Open;
   if not Q_Generica.EOF then
   begin
        Q_Generica.First;
        MioStream := TStream.Create;
        try
           if not Q_Generica.FieldByName('Immagine').IsNull then
           begin
                TBlobField(Q_Generica.FieldByName('Immagine')).SaveToStream(MioStream);
                MioStream.Position := 0;
                Img_Modifica.Picture.LoadFromStream(MioStream);
           end
           else
           begin
                Img_Modifica.Picture.Clear;
           end;
        finally
               MioStream.Free;
        end;
   end
   else
   begin
        Img_Modifica.Picture.Clear;
   end;
   Q_Generica.Close;

end;


On this row: TBlobField(Q_Generica.FieldByName('Immagine')).SaveToStream(MioStream);

compare this error

Writing to stream is not support


Why?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2001
    • Lazarus and Free Pascal italian community
Re: Blob and image importation
« Reply #5 on: November 26, 2010, 08:32:38 am »
Solved when:


procedure TForm2.Grid_DettaglioGiornoCellClick(Column: TColumn);
var
   MioStream: TStream;
   IdNota: integer;
begin

   IdNota:=Grid_DettaglioGiorno.DataSource.DataSet.FieldByName('IdNota').AsInteger;

   Q_Generica.SQL.Text:='Select Immagine FROM T_Scontrini Where IdNota=' + IntToStr(IdNota) + ';';
   Q_Generica.Open;
   if not Q_Generica.EOF then
   begin
        Q_Generica.First;
        //MioStream := TStream.Create;
        try
           if not Q_Generica.FieldByName('Immagine').IsNull then
           begin
                //TBlobField(Q_Generica.FieldByName('Immagine')).SaveToStream(MioStream);
                MioStream := Q_Generica.CreateBlobStream(Q_Generica.FieldByName('Immagine'),bmRead);
                MioStream.Position := 0;
                Img_Modifica.Picture.LoadFromStream(MioStream);
           end
           else
           begin
                Img_Modifica.Picture.Clear;
           end;
        finally
               MioStream.Free;
        end;
   end
   else
   begin
        Img_Modifica.Picture.Clear;
   end;
   Q_Generica.Close;
end;               
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1