Recent

Author Topic: Firebird 2.5 - load and save images to blob field  (Read 9434 times)

rc.1990

  • Jr. Member
  • **
  • Posts: 54
Firebird 2.5 - load and save images to blob field
« on: September 27, 2016, 06:06:58 pm »
I am using Lazarus 1.6, FPC 3.0.0 and Firebird 2.5.

How can I load and save images to Firebird 2.5 blob field using TIBConnection, TSQLTransaction, TSQLQuery and a TImage component?

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Firebird 2.5 - load and save images to blob field
« Reply #1 on: September 27, 2016, 06:14:11 pm »
Perhaps this can work for you as a start for reading blob-fields (the write would be similar but the other way around) ?

Keep in mind though, i'm not into databases so also can't help you out with those parts.
« Last Edit: September 27, 2016, 06:25:04 pm by molly »

rc.1990

  • Jr. Member
  • **
  • Posts: 54
Re: Firebird 2.5 - load and save images to blob field
« Reply #2 on: September 27, 2016, 10:34:39 pm »
Thanks molly.

I am trying to port a function, without success, that works on Delphi.

I have changed the Delphi unit JPeg to Lazarus unit Graphics, and
Code: Pascal  [Select][+][-]
  1. uses ...
  2.      Graphics,
  3.      LCLType, // HBitmap type
  4.      IntfGraphics, // TLazIntfImage type
  5.      fpImage, // TFPColor type
  6.      FPReadJpeg, FPWriteJpeg; // jpg support    
  7.  

Code: Pascal  [Select][+][-]
  1. procedure LoadImageFromField(Image: TImage; ImageField: TBlobField);
  2. var
  3.   MemStrm:    TMemoryStream;
  4.   Jpg:        TJPEGImage;
  5. begin
  6.     if ImageField.IsNull then
  7.     begin
  8.       Image.Picture.Assign(nil);
  9.       Exit;
  10.     end; //if
  11.     Jpg := TJPEGImage.Create;
  12.     try
  13.       MemStrm := TMemoryStream.Create;
  14.       try
  15.         ImageField.SaveToStream(MemStrm);
  16.         MemStrm.Seek(0,soFromBeginning);
  17.         with Jpg do begin
  18.           PixelFormat := jf24Bit;
  19.           Scale := jsFullSize;
  20.           Grayscale := False;
  21.           Performance := jpBestQuality;
  22.           ProgressiveDisplay := True;
  23.           ProgressiveEncoding := True;
  24.           LoadFromStream(MemStrm);
  25.         end; //with
  26.         Image.Picture.Assign(Jpg)
  27.       finally
  28.         MemStrm.Free;
  29.       end; //try
  30.     finally
  31.       Jpg.Free;
  32.     end; // fim try finally
  33. end;
  34.  


But I am still receiving errors on some properties e values:

Compile Project, Target: TestImages.exe: Exit code 1, Errors: 7, Hints: 1
BasicRoutines.pas(433,26) Error: Identifier not found "jf24Bit"
BasicRoutines.pas(434,11) Error: Identifier not found "Scale"
BasicRoutines.pas(435,21) Error: No member is provided to access property
BasicRoutines.pas(437,11) Error: Identifier not found "ProgressiveDisplay"
BasicRoutines.pas(438,31) Error: No member is provided to access property


Can you help find the right units that seems to miss?

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Firebird 2.5 - load and save images to blob field
« Reply #3 on: September 27, 2016, 10:42:33 pm »
I apologize upfront in case i'm way off here, but can't you simply use Image.Picture.LoadFromStream ?

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Firebird 2.5 - load and save images to blob field
« Reply #4 on: September 28, 2016, 12:01:11 am »
hello,
rc.1990 have a look to my database example (in Lazarus\examples\Database\Image_Mushrooms ) :
Quote
[MushRoomsDatabase by Jurassic Pork using SQLite - January 2014
Updated for Firebird Embedded - August 2014

Features:
- Use SqlDb and lazreport components.
- Sqlite3 or Firebird embedded database DeadlyMushrooms with 5 mushrooms.
Sqlite3 will be tried first; if no Sqlite library is available, Firebird
embedded will be tried.
- It demonstrates:
- creating a new SQLite3 database with table if the db does not exist
- use of TSQLScript to run multiple SQL statements
- use of FBAdmin to restore Firebird backup (smaller than the live .fdb file)
on first run, useful for keeping your setup file small and compatible with
older Firebird versions
- The images are stored in blob field without extension at the beginning.
With this you can view blob images with database browser editor
(e.g. sqlite2009pro).
- In the database there is also a field with images links (filenames).
- The linked images are stored in the folder images of the project.
- You can see the linked images in a Timage.
- You can change the images in the database:
- for Tdbimage (image in db): double click on the component and choose your
image.
- for Timage (linked image): click on the button near the image filename
(you must be in edit mode).
- Transaction commits when you click on Tdbnavigator refresh button or on close
form.
- Small pictures of the mushrooms are in the sqlite3Database. Largest images are
in files in the folder images.
- Print button to print all the mushrooms (lazreport).
On each page you have:
- a title.
- the field common_name of the mushroom database.
- the field notes of the mushroom database.
- the field picture of the mushroom database (picture picture1).
- the picture of the field image_link (picture picture2).

The report name is Mushroom_Report.lrf/quote]

Friendly, J.P

Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: Firebird 2.5 - load and save images to blob field
« Reply #5 on: September 28, 2016, 07:10:12 am »
Compile Project, Target: TestImages.exe: Exit code 1, Errors: 7, Hints: 1
BasicRoutines.pas(433,26) Error: Identifier not found "jf24Bit"
BasicRoutines.pas(434,11) Error: Identifier not found "Scale"
BasicRoutines.pas(435,21) Error: No member is provided to access property
BasicRoutines.pas(437,11) Error: Identifier not found "ProgressiveDisplay"
BasicRoutines.pas(438,31) Error: No member is provided to access property


Can you help find the right units that seems to miss?

Lazarus TJPEGImage has not same properties like Delphi's has.
Look at: http://lazarus-ccr.sourceforge.net/docs/lcl/graphics/tjpegimage.html
Try replace lines or comment lines where you got errors.

rc.1990

  • Jr. Member
  • **
  • Posts: 54
Re: Firebird 2.5 - load and save images to blob field
« Reply #6 on: August 03, 2018, 01:46:55 pm »

 

TinyPortal © 2005-2018