Saturday, 23 June 2018

Xamarin Forms Making Intelligent Application

Step 1 : MainPage.Xaml
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Image x:Name="MyImage" Grid.Row="0" Margin="24"/>
<ActivityIndicator x:Name="MyActivityIndicator" Grid.Row="1"/>
<ScrollView Grid.Row="2">
<Label x:Name="MyLabel"/>
</ScrollView>
<Button x:Name="MyButton" Grid.Row="3" Text="See4Me" Clicked="Handle_Click" BorderRadius="4"/>
</Grid>
</ContentPage.Content>
view raw MainPage.xaml hosted with ❤ by GitHub
Step2: MainPage.Xaml.cs
private async Task<AnalysisResult> GetImageDescription(Stream imageStream)
{
VisionServiceClient visionClient = new VisionServiceClient("4d673d0f18bc......add your keys", "https://westcentralus......add your endpoint");
VisualFeature[] features = { VisualFeature.Tags };
return await visionClient.AnalyzeImageAsync(imageStream, features.ToList(), null);
}
private async Task SelectPicture()
{
if (CrossMedia.Current.IsPickPhotoSupported)
{
var image = await CrossMedia.Current.PickPhotoAsync();
MyImage.Source = ImageSource.FromStream(() =>
{
return image.GetStream();
});
MyActivityIndicator.IsRunning = true;
try
{
var result = await GetImageDescription(image.GetStream());
foreach (var tag in result.Tags)
{
MyLabel.Text = MyLabel.Text + tag.Name + "\n";
}
}
catch (ClientException ex)
{
MyLabel.Text = ex.Message;
}
// await CrossTextToSpeech.Current.Speak(MyLabel.Text);
MyActivityIndicator.IsRunning = false;
}
}
async void Handle_Click(object sender, EventArgs e)
{
await SelectPicture();
// this.AnimationView.IsVisible = false;
}
}
}
Step 3: No More Codes Happy Coding :D

No comments:

Post a Comment