How do I convert a Bitmap to byte[]?

后端 未结 3 1714
囚心锁ツ
囚心锁ツ 2020-12-20 11:34

Basically I am inserting an image using the listviews inserting event, trying to resize an image from the fileupload control, and then save it in a SQL database using LINQ.<

3条回答
  •  天命终不由人
    2020-12-20 12:26

    You should be able to change this block to

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            newBMP.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
    
            PHJProjectPhoto myPhoto =
                new PHJProjectPhoto
                {
                    ProjectPhoto = stream.ToArray(), // <<--- This will convert your stream to a byte[]
                    OrderDate = DateTime.Now,
                    ProjectPhotoCaption = ProjectPhotoCaptionTextBox.Text,
                    ProjectId = selectedProjectId
                };
    

提交回复
热议问题