Closed redblox closed 8 years ago
Hi, You can do the same with an image as you do with the video data, have a look at the following gist on how to apply the orientation flag to the image:
When I use the Camera.instance.captureImage method it still saves in landscape mode. I can get it to work when I use the following. var cameraRoll: CameraRoll = new CameraRoll(); cameraRoll.addBitmapData(result); But the quality is not very good. Any ideas? Thank you for the fast response.
Thanks for the response.
How are you loading the saved image?
Generally this is considered correct, the image is saved in the orientation of the device and has an exif flag set indicating the orientation. You'll need to load it as you do any other image from the Camera roll and handle the exif orientation
I'm just viewing the saved photos in my camera Gallery, after I take the photo The resolution is 640x480 when I look at the details. I'm using the CameraMode.PRESET_PHOTO for best results.
When I use the Camera.instance.captureImage(true) method it saves the photo in a much higher resolution.
I may just be using the method wrong.
Again thanks for taking the time out to help.
Great ANE's BTW
But when I use the Camera.instance.captureImage(true) method it always saves the photo in my camera roll in landscape.
Hi,
That doesn't sound right. Can you post some more information on which platform you're testing on, the version of AIR and any details on the test devices?
Also can post some snippets on how you are initialising the camera?
I'm using air 15 SDK. I'm on a Android LG LS970.
Here is the script I 'm running.
import com.distriqt.extension.camera.Camera;
import com.distriqt.extension.camera.CameraMode;
import com.distriqt.extension.camera.CameraParameters;
import com.distriqt.extension.camera.CaptureDevice;
import com.distriqt.extension.camera.events.CameraDataEvent;
import com.distriqt.extension.camera.events.CameraEvent;
import com.distriqt.extension.camera.Orientation;
var lastFrameProcessed: Number = -1;
var videoData: ByteArray = new ByteArray();
var bitmapData: BitmapData = new BitmapData(640, 640, false);
var bitmap: Bitmap = new Bitmap(bitmapData);
addChild(bitmap);
var cameraCount = 0;
var dev_key: String = "";
var frontCam = true;
var options: CameraParameters = new CameraParameters();
var devices: Array;
function getCameraScreen(): void {
devices = [];
com.distriqt.extension.camera.Camera.init(dev_key);
lastFrameProcessed = -1;
options.enableFrameBuffer = true;
options.frameBufferWidth = 650;
options.frameBufferHeight = 650;
devices = [];
if (cameraCount == 0) {
frontCam = false;
} else {
frontCam = true;
}
devices = com.distriqt.extension.camera.Camera.instance.getAvailableDevices();
var device: com.distriqt.extension.camera.CaptureDevice = devices[cameraCount];
options.deviceId = device.id;
com.distriqt.extension.camera.Camera.instance.initialise(options);
options.cameraMode = new CameraMode(CameraMode.PRESET_PHOTO);
com.distriqt.extension.camera.Camera.instance.addEventListener(CameraEvent.VIDEO_FRAME, camera_videoFrameHandler, false, 0, true);
com.distriqt.extension.camera.Camera.instance.addEventListener(CameraDataEvent.CAPTURED_IMAGE, camera_capturedImageHandler, false, 0, true);
com.distriqt.extension.camera.Camera.instance.setFocusMode(CameraParameters.FOCUS_MODE_CONTINUOUS);
com.distriqt.extension.camera.Camera.instance.setExposureMode(CameraParameters.EXPOSURE_MODE_CONTINUOUS);
com.distriqt.extension.camera.Camera.instance.setWhiteBalanceMode(CameraParameters.WHITE_BALANCE_MODE_AUTO);
}
}
function camera_videoFrameHandler(event: CameraEvent): void {
var frame: Number = com.distriqt.extension.camera.Camera.instance.receivedFrames;
if (frame != lastFrameProcessed) {
com.distriqt.extension.camera.Camera.instance.getFrameBuffer(videoData);
var rect: Rectangle = new Rectangle(0, 0, com.distriqt.extension.camera.Camera.instance.width, com.distriqt.extension.camera.Camera.instance.height);
if (bitmapData.width != com.distriqt.extension.camera.Camera.instance.width || bitmapData.height != com.distriqt.extension.camera.Camera.instance.height) {
bitmapData = new BitmapData(com.distriqt.extension.camera.Camera.instance.width, com.distriqt.extension.camera.Camera.instance.height, false);
//bitmap.bitmapData.dispose();
bitmap.bitmapData = bitmapData;
}
try {
bitmapData.setPixels(rect, videoData);
} catch (e: Error) {
trace("ERROR::setPixels: " + e.message);
}
videoData.clear();
lastFrameProcessed = frame;
}
}
function clickHandler(): void
{
applyOrientation(bitmapData, "6");
}
function applyOrientation(bitmapData: BitmapData, orientation: String): BitmapData {
/*
1) transform="";;
2) transform="-flip horizontal";;
3) transform="-rotate 180";;
4) transform="-flip vertical";;
5) transform="-transpose";;
6) transform="-rotate 90";;
7) transform="-transverse";;
8) transform="-rotate 270";;
*/
var w: int = bitmapData.width;
var h: int = bitmapData.height;
var scaleX: Number = 1;
var scaleY: Number = 1;
var rotateAngle: Number = 0;
switch (orientation) {
default:
case "1":
break;
case "2":
scaleX = -1;
break;
case "3":
rotateAngle = Math.PI;
break;
case "4":
scaleY = -1;
break;
case "5":
break;
case "6":
w = bitmapData.height;
h = bitmapData.width;
rotateAngle = Math.PI / 2;
break;
case "8":
w = bitmapData.height;
h = bitmapData.width;
rotateAngle = -Math.PI / 2;
break;
}
var matrix: Matrix = new Matrix();
matrix.translate(-bitmapData.width * .5, -bitmapData.height * .5);
matrix.scale(scaleX, scaleY);
matrix.rotate(rotateAngle);
matrix.translate(w * .5, h * .5);
var result: BitmapData = new BitmapData(w, h);
result.draw(bitmapData, matrix);
com.distriqt.extension.camera.Camera.instance.captureImage(true);
//var cameraRoll: CameraRoll = new CameraRoll();
//cameraRoll.addBitmapData(result);
return result;
//var cameraRoll: CameraRoll = new CameraRoll();
//cameraRoll.addBitmapData(result);
}
Sorry I'm confused as to what the issue is.
When you are using cameraroll to save the bitmap data, you are only saving the video frame buffer which is a much lower resolution image.
When you use captureImage(true) it saves the full quality image, using the native camera process which generally stores the data in the default orientation and applies an exif orientation flag.
Sorry for the confusion. The issue I'm having is when I use the CaptureImage method it only saves in landscape. How would I save a photo to the camera roll in portrait?
Again Thank you for taking the time out to help.
Can you send over one of the images that you've taken with the camera in portrait?
Here is an example of what i've taken. I try to use the orientation property but it doesn't seem to have any effect.
Hi, Can you email me the file? Just in case github strips out that data.
Here's the file. I've recreated the basic functionality. Like I said it only save's in the camera roll in landscape mode.
p.s I bought my ANE's as a package before the ane's were sold separately. Will I need to buy each ANE again or will I have an option to renew the whole suite?
Thanks.
On Mon, 12/1/14, Michael notifications@github.com wrote:
Subject: Re: [airnativeextensions] How do i take a photo in portrait mode? (#297) To: "distriqt/airnativeextensions" airnativeextensions@noreply.github.com Cc: "redblox" redblox@yahoo.com Date: Monday, December 1, 2014, 7:29 PM
Hi,
Can you email me the file? Just in case github strips out that data.
— Reply to this email directly or view it on GitHub.
I've sent it to ma@distriqt.com
I can rotate the videoData to view the camera feed in portrait, but it still saves the photo in landscape mode. Is there a way to rotate the photo to be viewed in portrait?
Thanks.