-
Notifications
You must be signed in to change notification settings - Fork 1
Get Image or Video
levching edited this page Apr 9, 2020
·
3 revisions
When you need to get an Image or a video from the device gallery, create and configure the AN_MediaPicker object. Based on what type of content you would like to pick, you may sue following constructors.
Allow only image files:
AN_MediaPicker picker = new AN_MediaPicker(AN_MediaType.Image);
Allow only video files:
AN_MediaPicker picker = new AN_MediaPicker(AN_MediaType.Video);
Allow image and video content:
AN_MediaPicker picker = new AN_MediaPicker(AN_MediaType.Image, AN_MediaType.Video);
The code snippet below will demonstrate option for a media picker configuration.
using SA.Android.Camera;
...
AN_MediaPicker picker = new AN_MediaPicker(AN_MediaType.Image);
/// Defines if multiple images picker is allowed.
/// The default falue is < c > false </ c >
picker.AllowMultiSelect = true;
/// Max thumbnail size that will be trsnafered to the Unity side.
/// The thumbnail will be resized before it sent.
/// The default falue is 512.
picker.MaxSize = 512;
/// Starts pick mdeia from a gallery flow.
picker.Show((result) => {
PrintPickerResult(result);
});
private void PrintPickerResult(AN_GalleryPickResult result) {
if (result.IsFailed) {
AN_Logger.Log("Picker Filed: " + result.Error.Message);
return;
}
AN_Logger.Log("Picked medai count: " + result.Media.Count);
foreach (var an_media in result.Media) {
AN_Logger.Log("an_media.Type: " + an_media.Type);
AN_Logger.Log("an_media.Path: " + an_media.Path);
AN_Logger.Log("an_media.Thumbnail: " + an_media.Thumbnail);
}
ApplyImageToGUI(result.Media[0].Thumbnail);
}
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();
}
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