quinta-feira, 29 de novembro de 2012

Handle Images

Today we're going to implement a way to save the images without having to have the actual image file.
We'll create a program that will look to a specified folder chosen by the user, then we will import the bytes of each image to a database, storing the bytes of the image and its name.
The code to get the bytes is very simple as you can see below:


private Byte[] GetImageBytes(string pathToImage)
        {
            if (File.Exists(pathToImage))
                return File.ReadAllBytes(pathToImage);

            return null;
        }

And then will be able to use those bytes to generate an image with the following code:


using (MemoryStream stream = new MemoryStream(GetImageBytes(SomePath)))
{
        pictureBox1.Image = System.Drawing.Image.FromStream(stream);
}

We can use this to prevent us from having a space consuming app.

Nenhum comentário:

Postar um comentário