Step 1 : MainPage.Xaml
Step2: MainPage.Xaml.cs
Step 3: No More Codes Happy Coding :D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
No comments:
Post a Comment