1-Is this the best way to save a photo?
I prefer, because it is in the database, it is accessible in any environment (local or remote / application or web), and it eliminates the problem of controlling 2 backups.
2-Ref. the quality? do we lose quality in the photo?
No, unless you use compression in the middle of the algorithm.
3-If it's a high resolution photo (eg 6000x4000 pixel, 24mb), can I run this process normally?
Yes. It may be slow by file size, but look for different threads to load the image so the application will not crash while loading.
If errors occur during the Select, which may be due to lack of memory or timeout, the SGDB will have settings to circumvent the situation.
4-Any kind of image works? (Jpge, PNG, BitMap and others?)
I believe that yes, I can not tell you about the "image" type of the sql server, but it must be based on VARBINARY. In another field of the table, save the file extension, there when the user saves, already saved in the correct format. Note: VARBINARY can save any type of file: EXE, DLL, ZIP, etc.
5-The process to the contrary, ie get the Byte array and convert to photo, would not it be a slow process?
It depends on the size of the array, but will only notice slowness if it is absurdly large.
I prefer to always save the images to the bank, and when I give the select, I do not search the image column. By loading the information on the screen, I display a "loading image" progress and open the thread that will give the select in that field. The same thing I do for files.
In the case of images, the following is an example of the functions I use:
byte [] for Image
public static Image ConvertByteToImage(byte[] pic)
{
if (pic != null)
{
try
{
MemoryStream ImageDataStream = new MemoryStream();
ImageDataStream.Write(pic, 0, pic.Length);
System.Drawing.Image img = System.Drawing.Image.FromStream(ImageDataStream,true);
return img;
}
catch
{
return null;
}
}
else return null;
}
Image to byte []
public static byte[] ConvertImageToByte(System.Drawing.Image foto, System.Drawing.Imaging.ImageFormat format )
{
if (foto != null)
{
using (MemoryStream stream = new MemoryStream())
{
foto.Save(stream, format);
//stream.Flush();
byte[] pic = stream.ToArray();
return pic;
}
}
else return null;
}