Things used in this project

Code

App.xamlC#
<Application
    x:Class="PicUpload.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:PicUpload"
    RequestedTheme="Light">
    <Application.Resources>
        <x:String x:Key="SubscriptionKey">YOUR_COGNITIVE_SERVICE_KEY</x:String>
        <x:String x:Key="BaseURI">https://api.projectoxford.ai/face/v1.0/persongroups</x:String>
        <x:String x:Key="StoragePath">https://function073638f08fcd.blob.core.windows.net/</x:String>
        <x:String x:Key="StorageAccountName">function073638f08fcd</x:String>
        <x:String x:Key="StorageAccountKey">YOUR_STORAGE_ACCOUNT_KEY</x:String>
    </Application.Resources>

</Application>
Objects and VariablesC#
private static readonly string StorageAccountName = Application.Current.Resources["StorageAccountName"].ToString();
private static readonly string StorageAccountKey = Application.Current.Resources["StorageAccountKey"].ToString();
private static readonly StorageCredentials cred = new StorageCredentials(StorageAccountName, StorageAccountKey);

public static readonly string storagePath = Application.Current.Resources["StoragePath"].ToString();
public static readonly CloudBlobContainer blobContainer = new CloudBlobContainer(new Uri(storagePath + "originals"), cred);
public static readonly CloudBlobContainer thumbContainer = new CloudBlobContainer(new Uri(storagePath + "thumbnails"), cred);
        
Image File From GalleryC#
        private async void btnPickFromFile_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker filePicker = new FileOpenPicker();
            filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            filePicker.ViewMode = PickerViewMode.Thumbnail;

            filePicker.FileTypeFilter.Clear();
            filePicker.FileTypeFilter.Add(".jpeg"); filePicker.FileTypeFilter.Add(".jpg");
            filePicker.FileTypeFilter.Add(".png"); filePicker.FileTypeFilter.Add(".gif");

            StorageFile file = await filePicker.PickSingleFileAsync();
            if (null != file)
            {
                string blobFileName = await updateToBlob(file);
                AddFaceToPerson(blobFileName);
            }
        }
Image File From CameraC#
        private async void btnPickFromCamera_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI dialog = new CameraCaptureUI();
            StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
            string blobFileName = await updateToBlob(file);
            AddFaceToPerson(blobFileName);
        }
Upload Image To Blob StorageC#
        private async Task<string> updateToBlob(StorageFile file)
        {
            CloudBlockBlob blob = null;
            string filename = null;
            BitmapImage bitmapImage = new BitmapImage();
            IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

            if (null != fileStream)
            {
                fileName = System.Guid.NewGuid() + "." + file.Name.Split('.').Last<string>();
                bitmapImage.SetSource(fileStream);
                
                // Show image in a image box - CapturedPhoto
                CapturedPhoto.Source = bitmapImage;
                
                await blobContainer.CreateIfNotExistsAsync();
                blob = blobContainer.GetBlockBlobReference(blobFileName);
                await blob.DeleteIfExistsAsync();
                await blob.UploadFromFileAsync(file);
            }
            return filename;
        }

Credits

418553
Achindra Bhatnagar
18 projects • 83 followers
Windows Kernel Hacker, IoT Hobbyist, Enthusiast, Developer and Dreamer
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog