cfclient.camera.getPicture

Note: The image quality of pictures taken using the camera on newer devices is quite good, and images from the Photo Album will not be downscaled to a lower quality, even if a quality parameter is specified. Encoding such images using Base64 can cause memory issues on many newer devices. Therefore, using FILE_URI for images captured is highly recommended.

Getting the image from the camera

By invoking the default camera application on the device, this function takes a photo using the camera as the source.

The following example shows how you can get an image from the camera using the getPicture function:

<cfset picture = cfclient.camera.getPicture(options, base64)>

The following example depicts the usage:

<cfclientsettings enableDeviceAPI=true>
<cfclient>
<cffunction access="public" name="getpiccam" returntype="void" >
<cfset opt = cfclient.camera.getOptions()>
<cfset response = cfclient.camera.getPicture(opt,true)>

<cfset response ='data:image/jpeg;base64,'+ response>
<cfset src_to_img("myimg", response)>
</cffunction>

</cfclient>

<button style="width:100;height:50" onclick="invokeCFClientFunction(' getpiccam',null)">Get a picture
</button>

<img style = "width:200; height:100;" id = "myimg"></img>

<script type="text/javascript">
function src_to_img(img_id,data_to_write)
{
document.getElementById(img_id).src=data_to_write;
}
</script>

In the above example, on the click of a button, the default camera application is opened and after capturing an image, the image is rendered in the <img> tag.

Note: If you pass true as a param indicating that the returned object should be a Base-64 encoded string, its content has to be prefixed with  “data:image/jpeg;base64,” before rendering it.

Method summary

getPicture(Options, base64)

  • returns – Returns the image file URI or a Base-64 encoded string
  • params
    •  Options – Object
    • base64 – A Boolean flag to indicate that the returned object should be a base-64 encoded string.

Format for the Options object

The following table has the list of the properties for the Options object (ColdFusion sets defaults for these properties):

Property

Type

allowEdit

Boolean

encodingType

JPEG or PNG

popoverOptions

Object

savePhotoToAlbum

boolean

Quality

Number (0-100)

Example

See Using the Camera APIs

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online