Jump to content

webcam


dkeene

Recommended Posts

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

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

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

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

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

  • 2 years later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...