question

6666666 avatar image
0 Votes"
6666666 asked JarvanZhang-MSFT edited

Is the `Image` has a thumb property to show thumb image?

The Image is too big. which is over 3mb

can the Image show only 100 * 100 pixel of it?

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

Hello,​

Welcome to our Microsoft Q&A platform!

Xamarin.Forms.Image doesn't provide the 'thumb' property. To compress the image's size, try to achieve the function on each platform.

For example, here is the related the code about resizing images on Android.

public static byte[] ResizeImageAndroid(byte[] imageData, float width, float height)
{
    // Load the bitmap
    Bitmap originalImage = BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length);
    Bitmap resizedImage = Bitmap.CreateScaledBitmap(originalImage, (int)width, (int)height, false);
    using (MemoryStream ms = new MemoryStream())
    {
        resizedImage.Compress(Bitmap.CompressFormat.Jpeg, 100, ms);
        return ms.ToArray();
    }
}

Official sample code:
https://github.com/xamarin/xamarin-forms-samples/blob/main/XamFormsImageResize/XamFormsImageResize/ImageResizer.cs

Best Regards,

Jarvan Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.