I want to create .NET MAUI application where I want to capture photo of my tooth and I will add slider for user once user drag slider left to right I want to fill tooth with braces based on slider dragging.
I was using skisharp but not able to achieve
does anybody has idea how to do this?
I had tried with SkiaSharp but below code is not working
`
namespace TeethBraces
{
public partial class MainPage : ContentPage
{
private byte[] _imageData;
private SKBitmap _bracesBitmap;
public MainPage()
{
InitializeComponent();
LoadBracesImage();
}
private async void LoadBracesImage()
{
try
{
Image image = new Image
{
Source = ImageSource.FromFile("braces.png")
};
using (var stream = await FileSystem.OpenAppPackageFileAsync("braces.png"))
{
if (stream != null)
{
_bracesBitmap = SKBitmap.Decode(stream);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error loading braces image: {ex.Message}");
}
}
public async Task<SKBitmap> ConvertImageSourceToBitmapAsync(ImageSource imageSource)
{
if (imageSource is FileImageSource fileImageSource)
{
// Get the file path from the FileImageSource
var filePath = fileImageSource.File;
// Open the file and decode it to SKBitmap
using var stream = await FileSystem.OpenAppPackageFileAsync(filePath);
return SKBitmap.Decode(stream);
}
throw new NotSupportedException("Unsupported ImageSource type");
}
private async void OnUploadPhotoClicked(object sender, EventArgs e)
{
var result = await FilePicker.Default.PickAsync();
if (result != null)
{
using (var stream = await result.OpenReadAsync())
{
using (var memoryStream = new MemoryStream())
{
await stream.CopyToAsync(memoryStream);
_imageData = memoryStream.ToArray();
}
UpdateImageSource();
}
}
}
private void OnSliderValueChanged(object sender, ValueChangedEventArgs e)
{
if (_imageData != null)
{
using (var memoryStream = new MemoryStream(_imageData))
{
using (var bitmap = SKBitmap.Decode(memoryStream))
using (var canvas = new SKCanvas(bitmap))
{
float percentage = (float)e.NewValue;
DrawBraces(canvas, bitmap.Width, bitmap.Height, percentage);
using (var image = SKImage.FromBitmap(bitmap))
using (var data = image.Encode())
{
_imageData = data.ToArray();
}
}
}
UpdateImageSource();
}
}
private void UpdateImageSource()
{
TeethImage.Source = ImageSource.FromStream(() => new MemoryStream(_imageData));
}
private void DrawBraces(SKCanvas canvas, int width, int height, float percentage)
{
if (_bracesBitmap != null)
{
using (var paint = new SKPaint())
{
paint.Color = new SKColor(255, 255, 255, (byte)(percentage * 255));
canvas.DrawBitmap(_bracesBitmap, new SKRect(0, 0, width, height), paint);
}
}
}
}
}
`