カメラ - xDeviceCamera

推奨のコーディングは以下の通りです。ビデオを撮っている場合、データはファイルとして (ReturnFile := true) 戻し、ReturnBase64String に FALSE を設定します。

Define_Com Class(#xDeviceCamera) Name(#CameraUse)

Evtroutine Handling(#COM_OWNER.Initialize)
  #ActivateCamera.Enabled := false
Endroutine

Evtroutine Handling(#CameraUse.Initialize)
  #ActivateCamera.Enabled := true
Endroutine

Evtroutine Handling(#ActivateCamera.Click)
  #CameraUse.Source := CAM
  #CameraUse.EnableImage := true
  #CameraUse.EnableVideo := false
  #CameraUse.SetImageSize( PORT #ImageSizeWidth.Value.AsInteger #ImageSizeHeight.Value.AsInteger )
  #CameraUse.SaveToPhotoGallery := true
  #CameraUse.ReturnBase64String := true
  #CameraUse.SetBase64ImageSize( PORT #Base64Width.Value.AsInteger #Base64Height.Value.AsInteger )
  #CameraUse.ReturnFile := true
  #CameraUse.AllowEdit := false
  #CameraUse.EnableAnnotation := true
  #CameraUse.VideoQuality := HIGH
  #CameraUse.VideoMaxDuration := #VideoMaxDuration.Value.AsNumber
  #CameraUse.OutputPath := #OutputPath
  #CameraUse.ActivateCamera()
Endroutine

Evtroutine Handling(#CameraUse.Completed) Status(#lstatus) Message(#message)
  If (#lstatus = OK)
    #GeneratedFile := #CameraUse.OutputFile
    #GeneratedFileUrl := #CameraUse.OutputUrl
    If (#CameraUse.IsImage)
      #GeneratedType := 'Image'
    Else
      #GeneratedType := 'Video'
    Endif

    If (#CameraUse.ImageAsBase64Data <> "")
      #Base64 := #CameraUse.ImageAsBase64Data
      #LastImage.FileName := "data:image/png;base64," + #CameraUse.ImageAsBase64Data
    Endif
  Else
    #Status := #message
  Endif
  #Status := #lstatus
Endroutine
 
Write to a local file (xDeviceFileWrite)
Define_Com Class(#xDeviceFileWrite) Name(#FileWriter)

Evtroutine Handling(#COM_OWNER.Initialize)
  #Write.Enabled := false
Endroutine

Evtroutine Handling(#FileWriter.Initialize)
  #Write.Enabled := true
Endroutine

Evtroutine Handling(#Write.Click)
  #FileWriter.FileName := '/recipes/appleStrudel'
  #FileWriter.FileType := BIN
  #FileWriter.FileEncoding := UTF8
  #FileWriter.DataEncoding := BASE64
  #FileWriter.Data := 'Add 3 eggs and 4 cups of sugar'
  #FileWriter.Write()
Endroutine

Evtroutine Handling(#FileWriter.Completed) Status(#returnedStatus) Message(#message)
  #Status := #returnedStatus
  If (#Status <> OK)
    #StatusMessage := #message
  Endif
Endroutine
 
Read a local file (xDeviceFileRead)
Define_Com Class(#xDeviceFileRead) Name(#FileReader)

Evtroutine Handling(#COM_OWNER.Initialize)
  #Read.Enabled := false
Endroutine

Evtroutine Handling(#FileReader.Initialize)
  #Read.Enabled := true
Endroutine

Evtroutine Handling(#Read.Click)
  #FileReader.FileName := '/recipes/chocolateCake'
  #FileReader.FileType := TEXT
  #FileReader.FileEncoding := UTF8
  #FileReader.DataEncoding := NONE
  #FileReader.Read()
Endroutine

Evtroutine Handling(#FileReader.Completed) Status(#returnedStatus) Data(#returnedData) Message(#message)
  #Status := #returnedStatus
  If (#Status = OK)
    #Data := #returnedData
  Else
    #StatusMessage := #message
  Endif
Endroutine