.NET MAUI -Kamera öffnet sich nicht auf Android 15 (funktioniert auf anderen Versionen)Android

Forum für diejenigen, die für Android programmieren
Anonymous
 .NET MAUI -Kamera öffnet sich nicht auf Android 15 (funktioniert auf anderen Versionen)

Post by Anonymous »

In meiner .NET MAUI -Anwendung habe ich die Möglichkeit, die Kamera mit Mediapicker.Capturephotoasync () zu öffnen. Die Kamera funktioniert bei anderen Android -Versionen gut, aber bei Android 15 wird sie nicht geöffnet.try
{
photo = await MediaPicker.CapturePhotoAsync();
if (photo != null)
{
var newFile = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using (var stream = await photo.OpenReadAsync())
using (var newStream = File.OpenWrite(newFile))
await stream.CopyToAsync(newStream);

profileImage.Source = newFile;
isPicture = true;
}
}
catch (Exception ex)
{
Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}");
}
< /code>
Ich habe auch den folgenden Ansatz ausprobiert, aber dies funktioniert auch nicht auf Android 15: < /p>
try
{
if (MediaPicker.Default.IsCaptureSupported)
{
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();

if (photo != null)
{
picPath = photo.FullPath;

// Open the photo as a stream
using Stream sourceStream = await photo.OpenReadAsync();

// Load the image using SkiaSharp
using SKBitmap originalBitmap = SKBitmap.Decode(sourceStream);

// Define the desired width and height
int desiredWidth = 800; // change as needed
int desiredHeight = 600; // change as needed

// Resize the image
using SKBitmap resizedBitmap = originalBitmap.Resize(new SKImageInfo(desiredWidth, desiredHeight), SKFilterQuality.High);

// Encode the resized image to a byte array
using SKImage image = SKImage.FromBitmap(resizedBitmap);
using SKData encodedData = image.Encode(SKEncodedImageFormat.Jpeg, 75); // 75 is the quality, you can change it
byte[] resizedImageBytes = encodedData.ToArray();

// Save the resized image to local storage
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
File.WriteAllBytes(localFilePath, resizedImageBytes);

// Set the image source
profileImage.Source = localFilePath;
isPicture = true;
isCamera = true;

// Update other variables
imageByteContents = new ByteArrayContent(resizedImageBytes);
}
else
{
isPicture = true;
isCamera = true;
}
isGallery = false;
}
}
catch (Exception exception)
{
Console.WriteLine($"CapturePhotoAsync THREW: {exception}");
}
< /code>
Mein Problem ist, dass die Kamera bei Android 15 nicht geöffnet wird, während sie bei anderen Android -Versionen gut funktioniert. Bitte schlagen Sie eine Lösung vor.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post