0

The question: how can I save the image that is the image control (Name Photo) that is in bmp format for the database in SQL Server from UWP and C#?

class.cs

public BitmapImage Picture { get; set; }

Code C# SQL: I would be missing the equal part of the code

cmd.Parameters.Add("@picture", SqlDbType.Image).Value =;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    The `image` datatype has been deprecated since **2005**; don't use it any more. If you need to store binary data, use a `(var)binary`. – Thom A Jun 08 '22 at 14:42
  • refers to the BitmapImage part as I can save the (var)binary image – javier ramos lopez Jun 08 '22 at 14:45
  • I refer to `SqlDbType.Image` not, "bitmap image". – Thom A Jun 08 '22 at 14:49
  • So the real question is how to get the bytes of that `BitmapImage` class? That type represents the bytes to draw to the screen and can't be stored anywhere. You need an Encoder to convert it to JPG, PNG or any other type you want. You can save it to a `MemoryStream` and pass the bytes to the query. If the image is large, you can save it to a temporary location, open the file as a stream and pass the stream as the parameter value – Panagiotis Kanavos Jun 08 '22 at 14:54
  • when I choose the image that is in jpg, png or gif format I convert it to bitmap to be displayed in the Image control by the as much As I can insert the bmp image (Bitmap) in the Database – javier ramos lopez Jun 08 '22 at 16:09

0 Answers0