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
        navControl.activateNext();
        //return the String code to caller
        return base64String;
    }
}

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

--Edit
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

commented: Thanks the second method was perfect. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.