C
C#7mo ago
arkqa

Uploading a picture, clicking a pixel and getting it's colour (Xamarin.Forms)

I have a problem, I need help with a program that allows you to upload a picture from your computer and displays it, after that if you click a certain pixel you would get it's colour in rgb or hex value. I implemented uploading a picture but got stuck and i have no clue how to continue.
1 Reply
arkqa
arkqa7mo ago
Current code: Xaml: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="App2.MainPage"> <StackLayout> <Button Text="Select a picture" Clicked="OnPickPhotoButtonClicked" /> <Image x:Name="myImage"> <Image.GestureRecognizers> <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/> </Image.GestureRecognizers> </Image> <Label x:Name="wspol" Text="Position" /> </StackLayout> </ContentPage> C#: using Xamarin.Essentials; using Xamarin.Forms; using System; using System.IO; using System.Threading.Tasks; namespace App2 { public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); } private async void OnPickPhotoButtonClicked(object sender, EventArgs e) { try { var result = await MediaPicker.PickPhotoAsync(); if (result != null) { using (var stream = await result.OpenReadAsync()) { byte[] imageData = new byte[stream.Length]; await stream.ReadAsync(imageData, 0, (int)stream.Length); ImageSource imageSource = ImageSource.FromStream(() => new MemoryStream(imageData)); myImage.Source = imageSource; } } } catch (Exception ex) { await DisplayAlert("Błąd", $"Wystąpił błąd: {ex.Message}", "OK"); } } private void TapGestureRecognizer_Tapped(object sender, EventArgs e) {

} } }
Microsoft
Xamarin | Open-source mobile app platform for .NET
Xamarin is a free and open source mobile app platform for building native and high-performance iOS, Android, tvOS, watchOS, macOS, and Windows apps in C# with .NET.