6
I am working on a project where I have to save some photos. So I am studying the best way to accomplish the task.
I thought about saving in the database, because these photos will be accessed both locally (Winforms application) and via internet (MVC Asp.Net Application).
So I found a solution that consists of turning the photo into a Array
of Byte
, according to the code below:
MemoryStream stream = new MemoryStream();
meuPictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] foto = stream.ToArray();
And then save in the database, where the table has the following characteristics:
CREATE TABLE [dbo].[Crm_Fotos]
(
[id] [int] IDENTITY(1,1) NOT NULL,
[nCrm] [int] NULL,
[Bfoto] [image] NULL,
PRIMARY KEY CLUSTERED
(
However, I’m having some doubts:
- This would be the best way to save a photo?
- Ref. the quality? We have loss of quality in the photo?
- If it’s a high-resolution photo (e.g.: 6000x4000 pixels, 24mb), I can perform this process normally?
- Any type of image works? (Jpeg, PNG, Bitmap and others?)
- The reverse process, namely to catch the
array
ofByte
and convert to photo, it would not be a slow process?
Thank you.
The suggestion to add column indicating the type of file is fundamental, especially for those types of images that do not have header.
– José Diz