06-05-2011 01:53 PM
Good day everyone. I am using the following code to take a snapshot from the webcam and then save it with a button. It works when I run the app in the AIR player but on the Playbook it's not accessing the camera, nothing shows up.
<?xml version="1.0" encoding="utf-8"?> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark" actionBarVisible="false" creationComplete="init()" overlayControls="false" tabBarVisible="false"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:Panel id="p" top="1" width="1024" height="600" backgroundAlpha="0.0" horizontalCenter="0"> <s:Panel id="imageViewer" top="-32" width="1024" height="600" backgroundAlpha="0.0" horizontalCenter="0"/> <s:Panel id="preview" top="-32" width="1024" height="600" backgroundAlpha="0.0" horizontalCenter="0"/> <DrawingArea xmlns="*" id="drawingArea" y="-32" width="100%" height="509"/> </s:Panel> <fx:Script> <![CDATA[ import com.tinkerlog.WebCam; import com.tinkerlog.util.Base64; import flash.media.Camera; import mx.core.UIComponent; import mx.graphics.codec.JPEGEncoder; import mx.graphics.codec.PNGEncoder; private var webCam:WebCam; private function init():void { webCam = new WebCam(1024, 600); var ref:UIComponent = new UIComponent(); preview.removeAllElements(); preview.addElement(ref); ref.addChild(webCam); } private function takeSnapshot():void { imageViewer.visible = true; preview.visible=false; imageViewer.width = preview.width; imageViewer.height = preview.height; var uiComponent : UIComponent = new UIComponent(); uiComponent.width = webCam.width; uiComponent.height = webCam.height; var photoData:Bitmap = webCam.getSnapshot(); var photoBitmap:BitmapData = photoData.bitmapData; uiComponent.addChild(photoData); imageViewer.removeAllElements(); imageViewer.addChild(uiComponent); } private function deleteSnapshot():void { imageViewer.removeAllElements(); } public function save():void { var bd:BitmapData = new BitmapData(p.width, p.height); bd.draw(this); var barr:ByteArray = (new PNGEncoder()).encode(bd); (new FileReference()).save(barr, "capture.png"); } ]]> </fx:Script> </s:View>
Solved! Go to Solution.
06-05-2011 04:54 PM - edited 06-05-2011 04:55 PM
You cant' take a pic yet, the BB SDK doesn't have the API for it, it will work desktop, because your using Adobes API to get an image, go to this thread here.
06-05-2011 06:14 PM
The author of this post http://supportforums.blackberry.com/t5/Tablet-OS-S
06-05-2011 07:23 PM
Don't forget, you need to add the permissions for it in your blackberry-tablet.xml file.
<action>use_camera</action>
It should prompt you when launching the app to allow permission to the camera. You might also want to add:
<action>access_shared</action>
You might want to take a look at this article.
06-05-2011 07:34 PM
Eureka! I had <action>access_shared</action> but didnt know about <action>use_camera</action>. Thats a great link, can't wait to do some bedtime reading on my PB! Many thanks John ![]()
06-05-2011 07:35 PM