Skip to content

Commit

Permalink
Merge pull request #703 from rhomobile/EB_WM_CAMERA_IMAGE_SRC_FIX
Browse files Browse the repository at this point in the history
Eb wm camera image src fix
  • Loading branch information
fgqw68 committed Sep 4, 2015
2 parents da8ffb1 + 7b8de74 commit 6d1fdbc
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 18 deletions.
116 changes: 108 additions & 8 deletions lib/commonAPI/mediacapture/ext/camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ The ebapi.js file is necessary for all single API inclusions.
</CONSTANT>
<!-- Camera Output Image Format -->
<CONSTANT name="OUTPUT_FORMAT_IMAGE" value="image" type="STRING">
<DESC>This shall provide the image path.</DESC>
<DESC>This shall provide the image uri. This can be used to display image directly on the page. An example is shown in the example section</DESC>
</CONSTANT>
<CONSTANT name="OUTPUT_FORMAT_DATAURI" value="dataUri" type="STRING">
<DESC>This is a base 64 encoding of the image and can be used to easily embed the image on the page or store the image in a database. On some consumer devices, captured image will be rotated 90 degrees while displaying.</DESC>
</CONSTANT>
<CONSTANT name="OUTPUT_FORMAT_IMAGE_PATH" value="imagePath" type="STRING">
<DESC>If this value used for setting the outputFormat property, the takePicture or capture API will return imageUri as the path to the saved image in the device. User can use this image path to transfer the file to an http server if required. An example is given to demonstrate, transferring a file to http server.</DESC>
</CONSTANT>
<!-- Camera Color Model -->
<CONSTANT name="COLOR_MODEL_RGB" value="rgb" type="STRING">
<DESC>A colour image is captured.</DESC>
Expand Down Expand Up @@ -194,7 +197,7 @@ The ebapi.js file is necessary for all single API inclusions.
</DESC_EB>

</PROPERTY>
<PROPERTY name="outputFormat" type="STRING" default="image">
<PROPERTY name="outputFormat" type="STRING" default="imagePath">
<VER_INTRODUCED>4.0.0</VER_INTRODUCED>
<PLATFORM>Android, iOS, WM, CE, WP8</PLATFORM>
<PLATFORM_EB>WM, CE, Android</PLATFORM_EB>
Expand Down Expand Up @@ -339,7 +342,8 @@ The ebapi.js file is necessary for all single API inclusions.
<PARAM name="imageUri" type="STRING">
<PLATFORM>Android, WM, CE, iOS, WP8</PLATFORM>
<PLATFORM_EB>Android, WM, CE</PLATFORM_EB>
<DESC>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device.On wp8,wm when 'outputFormat' is 'image' then imageUri shall have only Image name with \ sign, on WP8 ImageName shall be suffixed by DTF when 'outputFormat' is 'image', this image will have an auto-generated name. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, In Wp8 dataUri shall provide the thumbnail for the picture taken, It is recommended to use Image over dataUri </DESC>
<DESC>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device.On wp8,wm when 'outputFormat' is 'image' then imageUri shall have only Image name with \ sign, on WP8 ImageName shall be suffixed by DTF when 'outputFormat' is 'image', this image will have an auto-generated name. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, In Wp8 dataUri shall provide the thumbnail for the picture taken, It is recommended to use Image over dataUri. If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http. </DESC>
<DESC_EB>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http.</DESC_EB>
</PARAM>
<PARAM name="imageHeight" type="INTEGER">
<PLATFORM>Android, WM, CE, iOS, WP8</PLATFORM>
Expand All @@ -364,7 +368,8 @@ The ebapi.js file is necessary for all single API inclusions.
<PARAM name="image_uri" type="STRING" deprecated="true">
<PLATFORM>Android, WM, CE, iOS, WP8</PLATFORM>
<PLATFORM_EB>Android, WM, CE</PLATFORM_EB>
<DESC>It is recommended to use imageUri in preference to this parameter.On wp8,wm when 'outputFormat' is 'image' then image_uri shall have only Image name with \ sign, on WP8 ImageName shall be suffixed by DTF when 'outputFormat' is 'image'</DESC>
<DESC>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device.On wp8,wm when 'outputFormat' is 'image' then imageUri shall have only Image name with \ sign, on WP8 ImageName shall be suffixed by DTF when 'outputFormat' is 'image', this image will have an auto-generated name. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, In Wp8 dataUri shall provide the thumbnail for the picture taken, It is recommended to use Image over dataUri. If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http. </DESC>
<DESC_EB>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http.</DESC_EB>
</PARAM>
<PARAM name="image_height" type="INTEGER" deprecated="true">
<PLATFORM>Android, WM, CE, iOS, WP8</PLATFORM>
Expand Down Expand Up @@ -412,7 +417,8 @@ The ebapi.js file is necessary for all single API inclusions.
<DESC>Whether or not the image was successfully captured. The returned string will be one of 'ok' or 'error'.</DESC>
</PARAM>
<PARAM name="imageUri" type="STRING">
<DESC>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device, this image will have an auto-generated name.On wm when 'outputFormat' is 'image' then this field shall have only Image name with \ sign, If the specified 'outputFormat' was 'dataUri',then this field will be the image encoded as a Data URI.</DESC>
<DESC>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, In Wp8 dataUri shall provide the thumbnail for the picture taken, It is recommended to use Image over dataUri. If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http. </DESC>
<DESC_EB>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http.</DESC_EB>
</PARAM>
<PARAM name="imageHeight" type="INTEGER">
<DESC>The actual height of the image that was captured, this may differ from the requested height as the Camera will only support a finite resolutions.</DESC>
Expand Down Expand Up @@ -451,7 +457,8 @@ The ebapi.js file is necessary for all single API inclusions.
<PARAM name="imageUri" type="STRING">
<PLATFORM>Android, WM, CE, iOS, WP8</PLATFORM>
<PLATFORM_EB>Android, WM, CE</PLATFORM_EB>
<DESC>The URI to the chosen image.</DESC>
<DESC>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device.On wp8,wm when 'outputFormat' is 'image' then imageUri shall have only Image name with \ sign, on WP8 ImageName shall be suffixed by DTF when 'outputFormat' is 'image', this image will have an auto-generated name. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, In Wp8 dataUri shall provide the thumbnail for the picture taken, It is recommended to use Image over dataUri. If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http. </DESC>
<DESC_EB>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http.</DESC_EB>
</PARAM>
<PARAM name="imageHeight" type="INTEGER">
<DESC>The height of the image.</DESC>
Expand All @@ -468,7 +475,8 @@ The ebapi.js file is necessary for all single API inclusions.
<PARAM name="image_uri" type="STRING" deprecated="true">
<PLATFORM>Android, WM, CE, iOS, WP8</PLATFORM>
<PLATFORM_EB>Android, WM, CE</PLATFORM_EB>
<DESC>It is recommended to use imageUri in preference to this parameter.</DESC>
<DESC>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device.On wp8,wm when 'outputFormat' is 'image' then imageUri shall have only Image name with \ sign, on WP8 ImageName shall be suffixed by DTF when 'outputFormat' is 'image', this image will have an auto-generated name. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, In Wp8 dataUri shall provide the thumbnail for the picture taken, It is recommended to use Image over dataUri. If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http. </DESC>
<DESC_EB>If the specified 'outputFormat' was 'image' then this field is the URI to the taken image stored on the device. If the specified 'outputFormat' was 'dataUri' then this field will be the image encoded as a Data URI, If the specified 'outputFormat' was 'imagePath' then this field will have the image path on the device. User can use image path to transfer image over http.</DESC_EB>
</PARAM>
<PARAM name="image_height" type="INTEGER" deprecated="true">
<DESC>It is recommended to use imageHeight in preference to this parameter.</DESC>
Expand Down Expand Up @@ -854,7 +862,99 @@ alert(reslnArray[1].height);
</SECTION>
</SECTIONS>
</EXAMPLE>
</EXAMPLES>
<EXAMPLE title="Transfering an image to HTTP server">
<SECTIONS>
<SECTION>
<DESC>This example demonstrate how user can transfer an image to http server. This will be useful when application is running on a remote server.</DESC>
<CODE>
<JAVASCRIPT>
<![CDATA[
//enumerate the available cameras on the device
var camArray = EB.Camera.enumerate();
//below is the callback fired by network api after image upload to the server is completed
var upload_file_callback = function (args){
status = args['status'];
//a status ok indicates image transferred successfully
alert(status);
}
//below is the camera call back fired after takePicture is called
var camera_callbackFunc = function(cbData){
alert(cbData.imageUri);
//set the upload file properties; Refer network module for more details
var uploadfileProps = {
url: 'http://10.233.82.51:8081/upload_image_file',
//authType: "basic",
//authUser: "admin",
//authPassword: "password",
filename: cbData.imageUri,
body: "uploading file",
fileContentType: "image/jpeg"
};
//below is the network module API used for uploading images when camera fire the callback
EB.Network.uploadFile(uploadfileProps, upload_file_callback);
};
//below is the test function which is used for capturing an image with outputFormat set as imagePath
function Test_image_transfer1()
{
//invoke takePicture API with outputFormat as imagePath and set the callback method
camArray[0].takePicture({'fileName' : '/Application/Test/myImagename', 'outputFormat': 'imagePath'}, camera_callbackFunc);
}
//below is the test function which is used for choosing a picture from device with outputFormat set as imagePath
function Test_image_transfer2()
{
//invoke choosePicture API with outputFormat as imagePath and set the callback method
EB.Camera.choosePicture({'outputFormat': 'image'}, camera_callbackFunc);
}
]]>
</JAVASCRIPT>
</CODE>
</SECTION>
</SECTIONS>
</EXAMPLE>
<EXAMPLE title="Dispalying an image using image uri.">
<SECTIONS>
<SECTION>
<DESC>This example demonstrate how user can dispaly an image using image uri. The callback will return a image uri when outputFormat is set to 'image'</DESC>
<CODE>
<JAVASCRIPT>
<![CDATA[
//enumerate the available cameras on the device
var camArray = EB.Camera.enumerate();
//below is the camera call back fired after takePicture is called
var camera_callbackFunc = function(cbData){
//uri will have relative path info only
//user has to form the absolute local server path as shown below
uri = 'http://localhost:'+EB.System.localServerPort + cbData.imageUri;
//set the image uri to the image element
document.getElementById('imageUri').src = uri ;
};
//below is the test function which is used for capturing an image with outputFormat set as image
function Test_image_uri()
{
//invoke takePicture API with outputFormat as image and set the callback method
camArray[0].takePicture({'outputFormat': 'image'}, camera_callbackFunc);
}
]]>
</JAVASCRIPT>
</CODE>
</SECTION>
</SECTIONS>
</EXAMPLE>
</EXAMPLES>
<REMARKS>
<REMARK title="SDCard Access">
<DESC>The capability for SDCard has already been granted on build, and any capability added by you will be ignored. This being the case, the following extensions will always be able to write to the SD card by default.</DESC>
Expand Down
19 changes: 12 additions & 7 deletions lib/commonAPI/mediacapture/ext/platform/wm/src/Camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CCamera::CCamera(LPCTSTR szDeviceName)
LOG(INFO) + __FUNCTION__ + "Device name set as " + m_szDeviceName;
m_PreviewOn = false;
m_FlashMode = FALSE;
m_eOutputFormat = eImageUri;
m_eOutputFormat = eImagePath;
m_FileName = DEFAULT_FILENAME;
m_DesiredHeight = -1;
m_DesiredWidth =-1;
Expand Down Expand Up @@ -107,6 +107,10 @@ BOOL CCamera::getProperty(LPCTSTR szParameterName, WCHAR* szParameterValue)
{
wcscpy(szParameterValue, L"image");
}
else if(m_eOutputFormat == eImagePath)
{
wcscpy(szParameterValue, L"imagePath");
}
else
{
wcscpy(szParameterValue, L"dataUri");
Expand Down Expand Up @@ -213,13 +217,14 @@ BOOL CCamera::setProperty(LPCTSTR szPropertyName, LPCTSTR szPropertyValue)
{
m_eOutputFormat = eImageUri;
}
else
else if(cmp(szPropertyValue, L"dataUri"))
{
if(cmp(szPropertyValue, L"dataUri"))
{
m_eOutputFormat = eDataUri;
}
}
m_eOutputFormat = eDataUri;
}
else if(cmp(szPropertyValue, L"imagePath"))
{
m_eOutputFormat = eImagePath;
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ enum eTriggerEvents
};
typedef enum
{
eImageUri=0,
eImagePath=0,
eImageUri,
eDataUri
}eImageOutputFormat;
enum eImageFilePathErrorType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace rho {
(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1);
if(bRunningOnWM)
{
eImageOutputFormat eFormat = eImageUri;
eImageOutputFormat eFormat = eImagePath;
//get output format
typedef std::map<rho::String, rho::String>::const_iterator it_type;
for (it_type iterator = propertyMap.begin(); iterator != propertyMap.end(); iterator++)
Expand All @@ -99,6 +99,14 @@ namespace rho {
{
eFormat = eDataUri;
}
else if(cmp(convertToStringW(iterator->second).c_str(), L"image"))
{
eFormat = eImageUri;
}
else if(cmp(convertToStringW(iterator->second).c_str(), L"imagePath"))
{
eFormat = eImagePath;
}
break;

}
Expand Down Expand Up @@ -259,7 +267,7 @@ namespace rho {
UpdateErrorStatus(dwResult);
}
}
void UpdateCallbackStatus(rho::String status, rho::String message, rho::String imageUri, eImageOutputFormat eFormat =eImageUri, int nImageWidth =0, int nImageHeight =0)
void UpdateCallbackStatus(rho::String status, rho::String message, rho::String imageUri, eImageOutputFormat eFormat =eImagePath, int nImageWidth =0, int nImageHeight =0)
{
char imageHeight[6];
char imageWidth[6];
Expand Down

0 comments on commit 6d1fdbc

Please sign in to comment.