Recent

Author Topic: DBImage loading from blob  (Read 50774 times)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: DBImage loading from blob
« Reply #30 on: August 05, 2013, 08:01:50 am »
hello,

is someone interested by an example of new version of tdbimage (lazarus 1.1 svn after 1 may 2013) ?
(see screenshot in attachment)

In this example :
- Use SqlDb components.
- Sqlite3 database biolife with 5 fishes.
- The images are stored in blob field without extension at the beginning.
  With this you can view blob images with database browser editor (ex sqlite2009pro).
- In the database there is also a field with images links (filenames).
- You can see the linked images in a Timage.
- The linked images are stored in the folder images of the project.
- You can change the images in the database :
  - for Tdbimage double click on the component and choose your image.
  - for Timage click on the button near the image filename.(you must be in edit mode )
 
  To not store the extension at the beginning of the blob an empty procedure DBImage1DBImageWrite  is used :
 
Code: [Select]
procedure TForm1.DBImage1DBImageWrite(Sender: TObject; S: TStream;
  GraphExt: string);
begin

end;

  To detect the type of graphic when reading blob , magic number detection is used in DBImage1DBImageRead
 
Code: [Select]
procedure TForm1.DBImage1DBImageRead(Sender: TObject; S: TStream;
  var GraphExt: string);
  var val1,val2:  WORD;
  begin
   S.Seek(0, soFromBeginning);
   S.Read(val1,2);
   S.Position := 2;
   S.Read(val2,2);
   if (val1 = $4D42) then  GraphExt := 'bmp';
   if (val1 = $4947) and (val2 = $3846) then  GraphExt := 'gif';
   if (val1 = $5089) and (val2 = $474E) then  GraphExt := 'png';
   if (val1 = $D8FF) and (val2 = $E0FF) then  GraphExt := 'jpg';
   S.Seek(0, soFromBeginning);
end;   

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

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage loading from blob
« Reply #31 on: August 05, 2013, 08:34:42 am »
JP, sounds like a good idea for SQLDBTutorial4 on the wiki... or perhaps a page called TDBImage...

If you have a working demo, I think submitting it to the bugtracker as an example for a directory $(lazarusdir)\examples\database\TDBImage\ would be very nice - Lazarus can do with some more db demos.

One thing though: is your database free of any Borland/Embarcadero copyrighted material (images, text)? If not, perhaps time to write up our own fish facts...
(As for the sqlite database schema: even if that doesn't fall under the copyright exception about one single possible/logical way to do things, it would fall under interoperability exceptions: by providing this demo we can use/show interoperation with Delphi examples)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage loading from blob
« Reply #32 on: August 05, 2013, 08:44:08 am »
Oh, I'm perfectly willing to help with a wiki page/article... just don't want to start another tutorial by myself...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: DBImage loading from blob
« Reply #33 on: August 05, 2013, 10:15:38 am »
hello bigchimp,
Quote
One thing though: is your database free of any Borland/Embarcadero copyrighted material (images, text)?

do you think there is problem with copyright ?

1 - THe database is a sqlite3 database not an embarcadero database 

2 - Even if the contents of the database have parts of original fishfact borland demo, i don't see copyright in the pictures and the texts (borland demo)  :P . If Embarcadero is an  >:D  call a lawyer.
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage loading from blob
« Reply #34 on: August 05, 2013, 10:35:47 am »
Hi my porcine friend,

do you think there is problem with copyright ?
Not necessarily as it always is very subjective and depends on jurisdictions, judge/jury mood etc. However, to avoid the possibility of the consequences in 2. happening and getting bad publicity (and even perhaps questioning the rest of the code) I suggest we use some fish of our own ;) I'd be happy to come up with something.

1 - THe database is a sqlite3 database not an embarcadero database 
Agreed. Therefore the physical implementation of the schema is probably different than whatever Borland used (Paradox? Interbase?) which already differentiates them.
Also, regardless of the above: there's only a couple of ways or perhaps "one true way" to create a properly normalized db/a good example db so it doesn't matter if the schema is quite alike.

No problems there, I'd say.

2 - Even if the contents of the database have parts of original fishfact borland demo, i don't see copyright in the pictures and the texts (borland demo)  :P . If Embarcadero is an  >:D  call a lawyer.
Well yes, if it were my own project I might take that chance. However, there's more people watching and... well, what I said above.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: DBImage loading from blob
« Reply #35 on: August 06, 2013, 03:49:56 pm »
hello,
i have created a new sqlite3 Database for my project. It contains mushrooms. I haven't found jurassic mushrooms, then i have taken deadly mushrooms. All the texts and images come from wikipedia.

Features:
- Use SqlDb components.
- Sqlite3 database DeadlyMushrooms with 5 mushrooms.
- The images are stored in blob field without extension at the beginning.
  With this you can view blob images with database browser editor (ex sqlite2009pro).
- In the database there is also a field with images links (filenames).
- You can see the linked images in a Timage.
- The linked images are stored in the folder images of the project.
- You can change the images in the database :
  - for Tdbimage double click on the component and choose your image.
  - for Timage click on the button near the image filename.(you must be in edit mode )
- Transaction commit 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.

In attachment a screenshot of the project.   

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

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage loading from blob
« Reply #36 on: January 10, 2014, 12:37:39 pm »
Hi Jurassic Pork,

Haven't seen any mushrooms come up in the Lazarus examples directory... ;)

Just wondering if you had a chance to upload it as an example to the bugtracker... (especially as I'm fighting a bit with dbimage myself ;) )

Thanks,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: DBImage loading from blob
« Reply #37 on: January 10, 2014, 06:37:46 pm »
hello bigChimp,

i have MushRooms database project in a 7zip file but it is too big for this forum ( 260k > 250k)
where to upload it ?


Friendly J.P

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

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage loading from blob
« Reply #38 on: January 10, 2014, 06:42:31 pm »
You can attach it to a bug report in the bug tracker as a sample project for Lazarus db components.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: DBImage loading from blob
« Reply #39 on: January 10, 2014, 06:56:32 pm »
mantis free pascal bugtracker issue  0025511    :D
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage loading from blob
« Reply #40 on: January 10, 2014, 07:00:00 pm »
Great, thanks! POsted a comment there
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: DBImage loading from blob
« Reply #41 on: January 15, 2014, 03:19:34 am »
Hello BigChimp,

i have added a lazreport report in my Mushroom Database  and a print button to print the report with all the mushrooms in the database.
In each page of the report :
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

to do that :
i have patched the laz_class.pas of the lazreport component with this patch


new procedures in unit1.pas
Code: [Select]
procedure TForm1.frReport1DBImageRead(Sender: TObject; S: TStream;
  var GraphExt: string);
var val1,val2:  WORD;
begin
    S.Seek(0, soFromBeginning);
   S.Read(val1,2);
   S.Position := 2;
   S.Read(val2,2);
   if (val1 = $4D42) then  GraphExt := 'bmp';
   if (val1 = $4947) and (val2 = $3846) then  GraphExt := 'gif';
   if (val1 = $5089) and (val2 = $474E) then  GraphExt := 'png';
   if (val1 = $D8FF) and (val2 = $E0FF) then  GraphExt := 'jpg';
   S.Seek(0, soFromBeginning);
end;

procedure TForm1.frReport1EnterRect(Memo: TStringList; View: TfrView);
begin
    if View.Name = 'Picture2' then
       if   DBEdit1.Text <> '' then
  TFrPictureView(View).Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +
  'images' +  DirectorySeparator +  DBEdit1.Text);
end;   

original source of the database  with the sqlite3 Imagetest.db3 database is here

the modified or added files   in attachments


Friendly J.P

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

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: DBImage loading from blob
« Reply #42 on: January 16, 2014, 03:12:43 am »
they are some errors in the project.
A new archive of the project is available here

you need to register to see and download attachments in this forum.

here the  new readme of the project :
Quote
MushRoomsDatabase by Jurassic Pork - January 2014
Features:
- Use SqlDb and lazreport components.
- Sqlite3 database DeadlyMushrooms with 5 mushrooms.
- The images are stored in blob field without extension at the beginning.
With this you can view blob images with database browser editor (ex sqlite2009pro).
- In the database there is also a field with images links (filenames).
- You can see the linked images in a Timage.
- The linked images are stored in the folder images of the project.
- You can change the images in the database :
- for Tdbimage double click on the component and choose your image.
- for Timage click on the button near the image filename.(you must be in edit mode )
- Transaction commit 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

Notes :
Depending of your Lazarus version, you need to patch the following files before to load and compile the project :

1 - file lazarus/lcl/dbctrls.pp and file lazarus/lcl/include/dbimage.inc
add OnDBImageRead and OnDBImageWrite properties


2 - file lazarus/components/lazreport/source/lr_class.pas
add OnDBImageRead property

The file dbImage.patch contains the modifications in the files that may be you have to do.

you need to recompile ide after patches.



Friendly J.P
« Last Edit: January 16, 2014, 03:17:18 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage loading from blob
« Reply #43 on: January 16, 2014, 10:04:22 am »
Thanks JP, will have a look!
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage loading from blob
« Reply #44 on: January 17, 2014, 05:06:35 pm »
Nice example - glad it got into the Lazarus example programs ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018