dkeene Posted June 13, 2020 Share Posted June 13, 2020 Hi Being able to take pictures with a webcam seems to be a basic function on modern apps. Is there a way to check if the user's computer has a webcam and to snap an image with it using uniGUI? Currently i am using unigui desktop, but have not used the mobile version. I have seen references to this in the forum, but have not found any success. Thanks doug Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 13, 2020 Share Posted June 13, 2020 1) to check if the user's computer has a webcam there is a code on stackoverflow.com you can use. 2) To snap an image and save to server I use these pieces of code: Have those index.html, adapter-latest.js and main.js available to browser (fix path references in index.html) On your TUnimForm put a TUnimHTMLFrame (hfrWebCam) and a TUnimBitBtn (btnTakePicture) for hfrWebCam HTML.Strings = ( '<iframe id="webcamframe"' ' src="/files/webrtc/index.html" ' ' style="width:[width]px; height:[height]px; border:none;"></if' + 'rame>') before activating hfrWebCam you replace [width] and [height] like below: hfrWebCam.HTML.Text := StringReplace(hfrWebCam.HTML.Text, '[height]', IntToStr(UniApplication.ScreenHeight - 20), []); hfrWebCam.HTML.Text := StringReplace(hfrWebCam.HTML.Text, '[width]', IntToStr(UniApplication.ScreenWidth - 20), []); then for btnTakePicture: function tap(sender, e, eOpts) { Ext.get(sender.id).setVisible(false); var win = document.getElementById("webcamframe").contentWindow; ajaxRequest(frmWebcamm.btnTakePicture, "saveimg", ["img="+win.getPicture()]); } To save the picture create an AjaxEvent: procedure TfrmWebcamm.btnTakePictureAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); var SS: TStringStream; MS: TMemoryStream; FN: String; UploadDir: string; //frmCropImagem: TfrmCropImagem; LTextDetection: string; begin if SameText(EventName, 'saveimg') then begin SS := nil; MS := nil; FN := ''; try SS := TStringStream.Create(Params.Values['img']); MS := TMemoryStream.Create(); DecodeStream(SS, MS); UploadDir := TPath.Combine(UniServerModule.ServerRoot, 'protected\saveimg'); ForceDirectories(UploadDir); FN := TPath.Combine(UploadDir, LowerCase(TPath.GetGUIDFileName + '.jpg')); MS.SaveToFile(FN); LTextDetection := GoogleTextDetection(FN); if LTextDetection <> '' then TfrmChatm(frmChatm).edtChatMessage.Text := LTextDetection; Close; finally SS.Free; MS.Free; end; end; end; I hope it helps. index.html adapter-latest.js main.js Link to comment Share on other sites More sharing options...
dkeene Posted June 13, 2020 Author Share Posted June 13, 2020 Thanks, Mehemet for sharing and the quick reply! Does this only work on the Mobile unigui environment? Is your device working now? Thanks Doug Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 13, 2020 Share Posted June 13, 2020 It is a working code (mobile form) in production. But it should work on desktop also. Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 13, 2020 Share Posted June 13, 2020 But dont forget that all communication must be over https/ssl otherwise it will not work. This is browser requirement Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 15, 2020 Share Posted June 15, 2020 On 6/13/2020 at 7:55 PM, dkeene said: Does this only work on the Mobile unigui environment? Is your device working now? By the way just tested on desktop it works fine. Link to comment Share on other sites More sharing options...
dkeene Posted June 15, 2020 Author Share Posted June 15, 2020 Hi, Mehmet Is there any way you could send me a form ? I don't quite understand where to put the javascript attachments... Thank you much Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 15, 2020 Share Posted June 15, 2020 I dont have any access to laptop now. I will attach to this thread as I return on Wednesday. Link to comment Share on other sites More sharing options...
dkeene Posted June 15, 2020 Author Share Posted June 15, 2020 OK, thank you i will wait and I am trying to make this work, based on your post. Are you saying that the attached index.html, adapter-latest.js and main.js files need to reside on each remote computer? Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 15, 2020 Share Posted June 15, 2020 3 minutes ago, dkeene said: you saying that the attached index.html, adapter-latest.js and main.js files need to reside on each remote computer? no. just on your server. Its my bad English. I mean put them in a location your uniGUI server can see that is all. Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 17, 2020 Share Posted June 17, 2020 Compile this one. webcam.7z webcam.7z Link to comment Share on other sites More sharing options...
dkeene Posted June 17, 2020 Author Share Posted June 17, 2020 Thank you, Mehmet I will try this now! I hope i can get this working Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 18, 2020 Share Posted June 18, 2020 I just found a little late. There is already a component developed for webcam. I recommend you also have look into this. Link to comment Share on other sites More sharing options...
dkeene Posted June 18, 2020 Author Share Posted June 18, 2020 Thanks, Mehmet. I tried the link to the other solution but it has been removed ;(. I tried your solution but I get "Project webcam raised exception EIdOSSLCouldNotLoadSSLLibrary" have you heard of this? I have not seen it. Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 18, 2020 Share Posted June 18, 2020 you will need ssl dlls 64/32bit (FMSoft\Framework\uniGUI\SSL\dll) put them to your executable location You will require cert.pem, key.pem and root.pem to start SSL. https:// is required for webcam access by browser. Link to comment Share on other sites More sharing options...
dkeene Posted June 18, 2020 Author Share Posted June 18, 2020 so copy these files as they are (both dll from x64 and x86) right into the executable directory? Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 18, 2020 Share Posted June 18, 2020 Depending on your build. Copy x64 or x86 dlls (not both) into where your exe located. Link to comment Share on other sites More sharing options...
Taweesak Sodjit Posted October 1, 2022 Share Posted October 1, 2022 Thank... Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now