Recent

Author Topic: Save Image to Database runtime  (Read 1410 times)

magleft

  • Full Member
  • ***
  • Posts: 125
Save Image to Database runtime
« on: August 19, 2023, 05:02:06 pm »
Hi to all.
I am trying in the application I have made, to save in a database on runtime photos that I take with the camera. If I just select save, everything works fine.
With the help of appCameraDemo I made the following code but it doesn't work. The message that comes out after some time is:
  if no operation for a long time, the screen will enter the power saving state. About to exit camera or click on the screen to wake up.
And then return
       resultCode = RESULT_CANCELED :
          photo Canceled
I have set the camera resolution to 2MP although I would like more resolution.
If anyone can help...

Code: Pascal  [Select][+][-]
  1. procedure TFvisitland.Button16Click(Sender: TObject);
  2. begin
  3.   if IsRuntimePermissionGranted('android.permission.CAMERA') and
  4.      IsRuntimePermissionGranted('android.permission.WRITE_EXTERNAL_STORAGE') then
  5.   begin
  6.       Camera1.Filename :=GetNameFarmer ;
  7.       Camera1.RequestCode := 12345;
  8.       Camera1.TakePhoto;
  9.   end
  10.   else  ShowMessage('Sorry... Some Runtime Permission NOT Granted ...');
  11. end;
  12.  
  13. procedure TFvisitland.FvisitlandActivityResult(Sender: TObject;
  14.   requestCode: integer; resultCode: TAndroidResult; intentData: jObject);
  15. var
  16.   photoPath: string;
  17.   photo_id:integer;
  18. begin
  19.   if resultCode = RESULT_CANCELED then
  20.   begin
  21.     ShowMessage('Photo Canceled!')
  22.   end
  23.   else if resultCode = RESULT_OK then //ok...
  24.   begin
  25.     if requestCode = Camera1.RequestCode then
  26.     begin
  27.       photoPath:= Camera1.FullPathToBitmapFile ;
  28.       Bitmap1.ImageIdentifier :=Camera1.FullPathToBitmapFile ;
  29.       // FIND LAST RECORD
  30.       DbVisitLandPhoto.close;
  31.       DbVisitLandPhoto.OpenOrCreate(dbname);
  32.       DbVisitLandPhoto.select('Select max(IDEPISK3) from Episkepsi4;') ; // Find Last record
  33.       photo_id:=DbVisitLandPhoto.Cursor.GetValueAsInteger(0)    ;
  34.       Bitmap1.LoadFromFile(photoPath) ;
  35.       DbVisitLandPhoto.UpdateImage('EPISKEPSI4',
  36.       'FIGURE',    // FIELD OF IMAGE
  37.       'IDEPISK3',  // FIELD ID
  38.       Bitmap1,
  39.       photo_id);
  40.     end;
  41.   end
  42.   else
  43.     ShowMessage('Photo Fail!');
  44. end;
  45.  
  46.  
windows 10 64

Mongkey

  • Sr. Member
  • ****
  • Posts: 435
Re: Save Image to Database runtime
« Reply #1 on: September 15, 2023, 11:45:41 am »
You could consider saving path of camera pic with detail -> ex:visit1,25-5-2023 10:10:23, path, note. You could simply call picture by retrieving its path, as long as you are not changing its path.

Thank you.

magleft

  • Full Member
  • ***
  • Posts: 125
Re: Save Image to Database runtime
« Reply #2 on: September 16, 2023, 07:22:26 am »
Thanks for the reply, but it's not possible as my app shares the database with a windows program.
I'm thinking maybe it's the size of the files, so how could I reduce their size by maybe converting them to some other format.
windows 10 64

Mongkey

  • Sr. Member
  • ****
  • Posts: 435
Re: Save Image to Database runtime
« Reply #3 on: September 16, 2023, 07:50:55 am »
Creating web API is one of many solutions, you could upload your picture with detail using jhttpclient, but again using your first base64 image  :D -> 2MB image would take about 3-5 second to convert.
« Last Edit: September 16, 2023, 07:59:10 am by Mongkey »

kapibara

  • Hero Member
  • *****
  • Posts: 630
Re: Save Image to Database runtime
« Reply #4 on: September 16, 2023, 01:13:31 pm »
Check these forum threads how to save images in database as BLOB. Thats the usual way.

https://forum.lazarus.freepascal.org/index.php?topic=34191.0
https://forum.lazarus.freepascal.org/index.php?topic=17606.0
Lazarus trunk / fpc 3.2.2 / Kubuntu 24.04 - 64 bit

magleft

  • Full Member
  • ***
  • Posts: 125
Re: Save Image to Database runtime
« Reply #5 on: September 17, 2023, 06:04:49 pm »
Thanks. I will try.
Also i try to convert image to png

https://forum.lazarus.freepascal.org/index.php/topic,64591.0.html
« Last Edit: September 17, 2023, 06:07:35 pm by magleft »
windows 10 64

 

TinyPortal © 2005-2018