I have a form where the user can select an image (via a file dialogue) of any size which is then previewed in a pictureBox sized at 150px by 150px with the sizeMode of the pictureBox set to zoom any space that is then not occupied by the image is set to be fuscia.

I have my method which converts the contained image into a base64 string - However the image string is being created from the original full size image, NOT the scaled image.

Any suggestions would be welcomed as Googling has turned up no helpful results.

My code for converting to Base64 below:

public string ImageToBase64(Image image, ImageFormat format)
    using (MemoryStream ms = new MemoryStream())
        // Convert Image to byte[]
        image.Save(ms, format);
        byte[] imageBytes = ms.ToArray();
        // Convert byte[] to Base64 String
        string base64String = Convert.ToBase64String(imageBytes);
        // Set next button on the Navigation to be active
        //return the String code to caller
        return base64String;

Edited by dhatsah: adding code.

2 Years
Discussion Span
Last Post by Fenrir()

There might be a better way but i'm lazy so i loaded the image into the picturebox it ads the size mode and then i save and load the image from a temporary directory. Click Here this ensures that the sizemode is applied to the image

this might be a better way actually Click Here you can resize the image on the fly in your base64 method and then save it to the stream

Edited by Fenrir()

Votes + Comments
Thanks the second method was perfect.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.