Microsoft.Maui.Graphics icon indicating copy to clipboard operation
Microsoft.Maui.Graphics copied to clipboard

Wrong IImage height and width

Open enricobenedos opened this issue 3 years ago • 5 comments

Good morning,

we are trying to use this library as simple substitute of System.Drawing.Common on Linux. We use it for a very simple task: retrieving images (in our case .png) height and width but the returned numbers haven no sense.

Our code:

[HttpGet("{imgName}/dimensions")]
public ActionResult<dynamic> GetImageDimensions(string imgName)
{
    string imgFileName = Path.Combine(Directory.GetCurrentDirectory(), _configuration["ImagesPath"], imgName);
    float height, width;
    using (var stream = System.IO.File.OpenRead(imgFileName))
    {
        using IImage image = GraphicsPlatform.CurrentService.LoadImageFromStream(stream);
        height = image.Height;
        width = image.Width;
    }
    return new { Height = height, Width = width};
}
{
  "height": 218765840,
  "width": -1991225700
}

Here the image specs from Windows: image

We cannot understand if it is a bug or a strange measure unit. We found no docs about this package.

enricobenedos avatar Dec 03 '21 10:12 enricobenedos

Another info about the CurrentService instance if it helps image

enricobenedos avatar Dec 03 '21 10:12 enricobenedos

Give LoadImageFromStream the optional second parameter, to tell it the image type:

LoadImageFromStream(stream, ImageFormat.Png);

I'm guessing it didn't figure out that it was a png.

ToolmakerSteve avatar Dec 11 '21 02:12 ToolmakerSteve

Nothings change specifying the ImageFormat also because .png is the default.

enricobenedos avatar Dec 13 '21 14:12 enricobenedos

I'm having this error as well:

image

image

Ogglas avatar Dec 15 '21 09:12 Ogglas

also get wrong width & size and if change image format to save(png->jpeg), get error: System.NotImplementedException: 'The method or operation is not implemented.'

coader avatar Jan 27 '22 11:01 coader