Getting an Image object from a byte array

前端 未结 4 1195
Happy的楠姐
Happy的楠姐 2021-02-07 08:37

I\'ve got a byte array for an image (stored in the database). I want to create an Image object, create several Images of different sizes and store them back in the database (sa

4条回答
  •  难免孤独
    2021-02-07 08:53

    I thought I'd add this as an answer to make it more visible.

    With saving it back to a byte array:

        public Image localImage;
        public byte[] ImageBytes;
    
        public FUU_Image(byte[] bytes)
        {
            using (MemoryStream ImageStream = new System.IO.MemoryStream(bytes))
            {
                localImage = Image.FromStream(ImageStream);
            }
    
            localImage = ResizeImage(localImage);
    
            using (MemoryStream ImageStreamOut = new MemoryStream())
            {
                localImage.Save(ImageStreamOut, ImageFormat.Jpeg);
                ImageBytes = ImageStreamOut.ToArray();
            }
    
        }
    

提交回复
热议问题