Array

The Camera Application and the CameraUI Class

Must Read

Effective Methods to Repay Student Loans

Because of the high cost of college education, even scholarships and grants may not be enough to get students...

DVB-H

There is interest in the industry in delivering 3DTV services to mobile phones. It is perceived that simple lenticular...

Drawing Bitmaps

A bitmap is a 2D image, also known as a texture in the realm of 3D programming. Bitmap images...

Flash Builder ViewNavigator

Flash Builder and its Hero APIs provide functionality to handle view management. Create a new project under File→New→Flex Mobile project....

Gadgets and Other Online Deals At Amazon On Black Friday 2010

 The Internet is a good place where people can get information and be entertained by watching videos and reading...

Canon PowerShot G12, Raising the ISO: The Simple Solution

Let’s begin with the obvious ways to keep shooting when the lights get low. One option is to use the...
Admin
test

You can access the native camera within AIR. Your application needs to have the permission for it. In Flash Professional, select File→AIR Android settings→Permissions→Camera. In Flash Builder, select CAMERA under Mobile Settings→
Permissions.

The flash.media.CameraUI class is an addition to the ActionScript language to support the device’s native camera application. It is a subclass of the EventDispatcher class. It is only supported on AIR for mobile applications.

This object allows you to launch the native camera application to take an image or shoot a video while your AIR application moves to the background. The image is stored in the Gallery along with the other images.

To use this class, first you must verify that your device supports access to the camera by checking the CameraUI.isSupported property:

import flash.media.CameraUI;
if (CameraUI.isSupported == false) {
trace(“You cannot use the native camera.”);
return;
}

If camera access is supported, create an instance of the CameraUI class and call its launch function. This function expects one parameter of type MediaType to specify picture or video mode. Choosing a level of compression is not an option at the time of this writing:

import flash.media.MediaType;
var cameraUI:CameraUI = new CameraUI();
cameraUI.launch(MediaType.IMAGE);

The camera application is now active and in the foreground. The AIR application moves to the background.

To receive camera events, set listeners before launching the camera. A Media Event.COMPLETE is dispatched after a picture is taken, an Event.CANCEL if no media is selected, and an ErrorEvent if there is an error in the process:

cameraUI.addEventListener(MediaEvent.COMPLETE, onComplete);
cameraUI.addEventListener(Event.CANCEL, onCancel);
cameraUI.addEventListener(ErrorEvent.ERROR, onError);

Once the event is received, the camera application automatically closes and the AIR application moves back to the foreground.

function onComplete(event:MediaEvent):void {
var promise:MediaPromise = event.data as MediaPromise;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onError);
loader.loadFilePromise(promise);
}
function onImageLoaded(event:Event):void {
var bitmapData:BitmapData = Bitmap(event.target.content).bitmapData;
var bitmap:Bitmap = new Bitmap(bitmapData);
var isPortrait:Boolean = (bitmapData.height/bitmapData.width) > 1.0;
var forRatio:int = Math.min(stage.stageHeight, stage.stageWidth);
var ratio:Number;
if (isPortrait) {
ratio = forRatio/bitmapData.width;
} else {
ratio = forRatio/bitmapData.height;
}
bitmap.width = bitmapData.width * ratio;
bitmap.height = bitmapData.height * ratio;
if (!isPortrait) {
bitmap.y = stage.stageHeight;
bitmap.rotation = -90;
}
addChild(bitmap);
}

Uploading to a Remote Server

Images can be uploaded to a remote server if you have access to one. You need the Internet permission to add this functionality:

<uses-permission android:name=”android.permission.INTERNET” />

This process is identical to what you would do in a desktop application:

import flash.net.URLRequestMethod;
import flash.filesystem.File;
var request:URLRequest = new URLRequest(“server url”);
request.method = URLRequestMethod.POST;
var uploadFile:File = new File(promise.file.url);
uploadFile.upload(request);

 

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place...

What are 7 things poor people do that the rich don’t?

1. poor people watch TV in which people read books how many hours you spend in front of the TV and when...

Top 18 best small business ideas for beginners starting

A small business can be frightening and requires plenty of careful planning there are many small business ideas which can be beneficial...

Summer that makes you happy

We saw were already here I've been thinking about some of the things. I used to do with my husband even though...

4 Point to helpful tips specifically for caregivers

What you need to take a vacation. I know it sounds impossible creative and try to make it work for you almost...

More Articles Like This