arkqa
arkqa
CC#
Created by arkqa on 11/11/2023 in #help
Uploading a picture, clicking a pixel and getting it's colour (Xamarin.Forms)
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) {

} } }
2 replies