The user selects a picture for his avatar, for example, with a resolution of 1920 by 1080 and presses the button to load an image. The image is converted into a byte[] array and sent to the server. It is necessary on the server before writing a picture to a table to reduce its size to 100x100 pixels. And if the loaded image is less than 100x100, then do not touch it. How to know the size of the picture and reduce it if necessary?

    1 answer 1

    Found the answer HERE

    Here is the correct answer:

     byte[] imageBytes; //Of course image bytes is set to the bytearray of your image using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { using (Image img = Image.FromStream(ms)) { int h = 100; int w = 100; using (Bitmap b = new Bitmap(img, new Size(w,h))) { using (MemoryStream ms2 = new MemoryStream()) { b.Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg); imageBytes = ms2.ToArray(); } } } } 
    • Proportions may be distorted. - Alexander Petrov
    • @AlexanderPetrov in my case is not critical) but I would love to know how to keep the proportions of the image) - Leksor