Forum > Databases

Firebird 2.5 - load and save images to blob field

(1/2) > >>

rc.1990:
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:
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.

rc.1990:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ...     Graphics,      LCLType, // HBitmap type     IntfGraphics, // TLazIntfImage type     fpImage, // TFPColor type     FPReadJpeg, FPWriteJpeg; // jpg support      

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure LoadImageFromField(Image: TImage; ImageField: TBlobField);var  MemStrm:    TMemoryStream;  Jpg:        TJPEGImage;begin    if ImageField.IsNull then    begin      Image.Picture.Assign(nil);      Exit;    end; //if    Jpg := TJPEGImage.Create;    try      MemStrm := TMemoryStream.Create;      try        ImageField.SaveToStream(MemStrm);        MemStrm.Seek(0,soFromBeginning);        with Jpg do begin          PixelFormat := jf24Bit;          Scale := jsFullSize;          Grayscale := False;          Performance := jpBestQuality;          ProgressiveDisplay := True;          ProgressiveEncoding := True;          LoadFromStream(MemStrm);        end; //with        Image.Picture.Assign(Jpg)      finally        MemStrm.Free;      end; //try    finally      Jpg.Free;    end; // fim try finallyend; 

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:
I apologize upfront in case i'm way off here, but can't you simply use Image.Picture.LoadFromStream ?

Jurassic Pork:
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


--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version