You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Requirement :The MAUI android app allows users to capture / pick 75 images with any size and orientation. Here the challenge is to resize these 75 images into a standard size such that it fits the screen and the images maintain its aspect ratio. I have Already tried the below maui code by providing the desired width and height as 400x400 which proportionally resizes to 184x400 for an image of size 1080x2230.
public static async Task TakePhoto()
{
Stream stream = null;
try
{
// Check if picking a photo is supported
if (MediaPicker.IsCaptureSupported)
{
// Pick a photo
var photo = await MediaPicker.PickPhotoAsync(new MediaPickerOptions
{
Title = "Select a photo"
});
// Handle the selected photo
if (photo != null)
{
// Use the picked photo
stream = await photo.OpenReadAsync();
// For example, display the photo in an Image control
if (stream?.Length > 0)
{
// Copy the stream to a MemoryStream to ensure it's accessible
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
// Decode the image with SkiaSharp
using var skBitmap = SKBitmap.Decode(memoryStream);
using var originalImage = SKImage.FromBitmap(skBitmap);
FileInfo fileInfo = new FileInfo(photo.FullPath);
int imgSize = Convert.ToInt32(fileInfo.Length);
if (imgSize > 100000)
{
IImage newImage= image.Resize(184, 400, ResizeMode.Bleed, true);
canvas.DrawImage(newImage, 10, 10, newImage.Width, newImage.Height);
}
else
{
return stream;
}
}
}
}
else
{
await App.Current.MainPage.DisplayAlert("Error", "Photo picking is not supported on this device.", "OK");
}
}
catch (Exception ex)
{
}
return stream;
}
In the above method when I try to resize an image for example of dimensions [1080x2230] to the new dimensions [184x400] it doesn't maintain the aspect ratio there by resulting the output image to be blur.
PS: The frame size of 400x400 cannot be increased here due to the app design requirement constraints.
Any leads/ input on this would be of great help.
This discussion was converted from issue #28129 on March 03, 2025 15:45.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Requirement :The MAUI android app allows users to capture / pick 75 images with any size and orientation. Here the challenge is to resize these 75 images into a standard size such that it fits the screen and the images maintain its aspect ratio. I have Already tried the below maui code by providing the desired width and height as 400x400 which proportionally resizes to 184x400 for an image of size 1080x2230.
public static async Task TakePhoto()
{
Stream stream = null;
try
{
// Check if picking a photo is supported
if (MediaPicker.IsCaptureSupported)
{
// Pick a photo
var photo = await MediaPicker.PickPhotoAsync(new MediaPickerOptions
{
Title = "Select a photo"
});
// Handle the selected photo
if (photo != null)
{
// Use the picked photo
stream = await photo.OpenReadAsync();
// For example, display the photo in an Image control
if (stream?.Length > 0)
{
// Copy the stream to a MemoryStream to ensure it's accessible
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
// Decode the image with SkiaSharp
using var skBitmap = SKBitmap.Decode(memoryStream);
using var originalImage = SKImage.FromBitmap(skBitmap);
FileInfo fileInfo = new FileInfo(photo.FullPath);
int imgSize = Convert.ToInt32(fileInfo.Length);
if (imgSize > 100000)
{
IImage newImage= image.Resize(184, 400, ResizeMode.Bleed, true);
canvas.DrawImage(newImage, 10, 10, newImage.Width, newImage.Height);
}
else
{
return stream;
}
}
}
}
else
{
await App.Current.MainPage.DisplayAlert("Error", "Photo picking is not supported on this device.", "OK");
}
}
catch (Exception ex)
{
}
return stream;
}
In the above method when I try to resize an image for example of dimensions [1080x2230] to the new dimensions [184x400] it doesn't maintain the aspect ratio there by resulting the output image to be blur.
PS: The frame size of 400x400 cannot be increased here due to the app design requirement constraints.
Any leads/ input on this would be of great help.
Beta Was this translation helpful? Give feedback.
All reactions