Загрузка изображений из папки в .net MAUIAndroid

Форум для тех, кто программирует под Android
Ответить
Гость
 Загрузка изображений из папки в .net MAUI

Сообщение Гость »


Я пытаюсь отобразить изображения из такой папки:

Код: Выделить всё

 // Path to the folder containing photos
string folderPath = "";

// Get all the image file paths from the folder
string[] imagePaths = System.IO.Directory.GetFiles(folderPath, "*.png");

// Create a stack layout to hold the photo squares
StackLayout stackLayout = new StackLayout();

// Iterate through each image path
foreach (string imagePath in imagePaths)
{
// Create an image view with the current photo
Image photoImage = new Image
{
Source = ImageSource.FromFile(imagePath),
Aspect = Aspect.AspectFill // Adjust aspect ratio of the image
};

// Create a square container for the photo
Frame photoFrame = new Frame
{
CornerRadius = 10, // Optional: Round the corners of the frame
Padding = 5,
BackgroundColor = Colors.LightGray, // Optional: Set background color
Content = photoImage,
Margin = new Thickness(10) // Optional: Add margin between squares
};

// Add the photo square to the stack layout
stackLayout.Children.Add(photoFrame);
}
My objective is to have lots of images in a folder that need to be loaded in a page of a mobile app.
The problem is that while I know the correct path to the images when executing in windows, from an android phone I can't find the images in the application folder in /data.
Knowing that the path needed by

Код: Выделить всё

System.IO.Directory.GetFiles(folderPath, "*.png");
is an absolute path, so I thought about putting all the images in a known folder, but i have no idea on how to do that and it may be a substantial amount of images.
I am new to MAUI and I have never worked with applications before, and I know that it probably is an extremely easy fix, but I can't seem to find a way.


Источник: https://stackoverflow.com/questions/781 ... n-net-maui
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»