Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get image size from base64 in C# [duplicate]

Tags:

c#

image

base64

How to get image size from base64 in C#?

Is it possible to do at all?

like image 292
Friend Avatar asked Aug 31 '25 03:08

Friend


1 Answers

Not directly as it depends on what data/format is encoded in the Base64 string. A rough approach would be (code not tested):

byte[] image = Convert.FromBase64String("Your Base64 string here");
using (var ms = new MemoryStream(image))
{
    Image img = Image.FromStream(ms);
    return new Tuple<int, int>(img.Width, img.Height); // or some other data container
}

Note: Image class comes from System.Drawing. See also the MSDN System.Drawing.Image class' documentation documentation.

like image 82
Gigabyte Avatar answered Sep 02 '25 17:09

Gigabyte