-
Notifications
You must be signed in to change notification settings - Fork 1
Camera API
The article will describe camera related API available with the plugin. Make sure that camera service is enabled inside the Plugin Editor UI.
The code example below will demonstrate how to allow a user to capture a photo with the device camera and then use it inside Unity app.
using SA.Android.Camera;
...
int maxSize = 1024;
AN_Camera.CaptureImage(maxSize, (result) => {
PrintCaptureResult(result);
});
private void PrintCaptureResult(AN_CameraCaptureResult result) {
if (result.IsFailed) {
AN_Logger.Log("Filed: " + result.Error.Message);
return;
}
AN_Logger.Log("result.Media.Type: " + result.Media.Type);
AN_Logger.Log("result.Media.Path: " + result.Media.Path);
AN_Logger.Log("result.Media.Thumbnail: " + result.Media.Thumbnail);
ApplyImageToGUI(result.Media.Thumbnail);
AN_Camera.DeleteCapturedMedia();
}
private void ApplyImageToGUI(Texture2D image) {
//m_image is a UnityEngine.UI.RawImage
m_image.texture = image;
//m_sprite is a UnityEngine.UI.Image
m_sprite.sprite = image.ToSprite();
}You may use the same approach for the video capturing
using SA.Android.Camera;
...
int maxSize = 1024;
AN_Camera.CaptureVideo(maxSize, (result) => {
PrintCaptureResult(result);
});
private void PrintCaptureResult(AN_CameraCaptureResult result) {
if (result.IsFailed) {
AN_Logger.Log("Filed: " + result.Error.Message);
return;
}
AN_Logger.Log("result.Media.Type: " + result.Media.Type);
AN_Logger.Log("result.Media.Path: " + result.Media.Path);
AN_Logger.Log("result.Media.Thumbnail: " + result.Media.Thumbnail);
ApplyImageToGUI(result.Media.Thumbnail);
AN_Camera.DeleteCapturedMedia();
}
private void ApplyImageToGUI(Texture2D image) {
//m_image is a UnityEngine.UI.RawImage
m_image.texture = image;
//m_sprite is a UnityEngine.UI.Image
m_sprite.sprite = image.ToSprite();
}There is one more thing you should know. Since the native part is transferring only scale thumbnails of captured media (scaled according to the maxSize property value). You may what to have an access to the actually captured media (image or video), that's why we have a Path property inside the AN_Media object. When you no longer need a saved media, you can simply delete it using the DeleteCapturedMedia method.
using SA.Android.Camera;
...
AN_Camera.DeleteCapturedMedia();Reliable and high-quality Unity Development service. Let's Talk!
Website | AssetStore | LinkedIn | Youtube | Scripting Reference
- Build Info
- Dark Mode
- Package Info
- Runtime Permissions
- Run External App
- Immersive Mode
- PackageManager
- Popups & Preloaders
- Rate Us Dialog
- Activity
- Intent
- Settings Page
- Media Player
- Date Picker Dialog
- Time Picker Dialog
- Locale
- Wheel Picker Dialog
- Developer Console Setup
- Connecting to The Service
- Purchase Flow
- Transactions Validation
- Subscriptions
- Licensing
- Getting Started
- Games Sing-in
- Server-side API Access
- Leaderboards
- Achievements
- Saved Games
- Image Manager
- Settings Intent