Get image from mobile camera or picture gallery

Hi!


I'm trying to set the TWebImageControl image from a mobile picture gallery or camera. I see no WEB Core to do this, so I'm trying to do it via JS, but I ecountered some problems:

This JS code works OK, but don't know where/how to put it in the form code:

Contol on the form TWebHtmlContainer

<label class="btn btn-xl btn-success">
    Add picture <input type="file" hidden name="imgFile" accept="image/gif, image/jpeg, image/png, image/bmp, image/tiff, image/tif, image/jfif, image/jpe">
</label>


JS that works in a test form (outside the project)


  <script>
$(":file").change(function () {
    if (this.files && this.files[0]) {
        var reader = new FileReader();
        reader.onload = imageIsLoaded;
        reader.readAsDataURL(this.files[0]);
    }
});


function imageIsLoaded(e) {
    $('img').attr('src', e.target.result);
    $('img').fadeIn();
};
  </script>


You can test it here: https://jsfiddle.net/KyleMit/d3H9f/

How to do this with web core? Or alternatively - how to add JS to the form so it will accept images?
  1. To assign an image picked from the local file system to a TWebImageControl:

    procedure TForm1.WebFilePicker1Change(Sender: TObject);
    begin
      WebFilePicker1.Files[0].GetFileAsBase64;
    end;

    procedure TForm1.WebFilePicker1GetFileAsBase64(Sender: TObject;
      AFileIndex: Integer; ABase64: string);
    var
      imgbase64: string;
    begin
      imgbase64 := 'data:image/png;base64,' + ABase64;
      WebImageControl1.URL := imgbase64;
    end;

    2) To assign an image taken from a camera to a TWebImageControl:

    begin
      WebImageControl1.URL := WebCamera1.SnapShotAsBase64;
    end;



    Bruno Fierens2019-10-16 10:15:02

Hi!


I don't have the TWebCamera component. I uninstalled TMS web core and reinstalled, biut the component is still missing.

I also opened the camer_basic demo and the project raises the error that the componenet is missing. Is there any special way to add the component? I checked the manual, but I don't see any special notes.

Can you give me any advice to fix the missing component?

I cannot understand why you would not have TWebCamera installed. It is registered just like all other components. Is this v1.2.8.0 you use? Are you sure there are no more old version .BPL files around on your system?

No, no - I would like to use TWebCamera, it's just missing the component.


Anyway, I repeated the procedure with the BPLs in mind - I uninstalled the pack, removed the directory and reinstalled it. Using latest version (1.2.8.0) - and now the camera component is present. Tested on BasiccCamera demo and it compiled.

Case closed, detective Bruno :)

:+1: