Resize image returned by api

I have an API that returns an image from a byte array via a memory stream at the moment. I want to update it to return an image at a specific width and height given some inputs. What I'm not sure though, is how I manipulate the memory stream to say, the image is x wide and y tall. Here's the code now.

//dt is a data table with 1 row and 1 column. That column is the image stored as bytes in the database. byte[] imgData = GetImgBytes(); WebOperationContext.Current.OutgoingResponse.ContentType = "image/png"; //DO NOT try to dispose of the memory stream or put it in a using. Putting it in there will make it dispose of it before it returns it. MemoryStream ms = new MemoryStream(imgData); //############################################################## //not sure how I'd change the width and height here. originally I was just returning ms Image img = Image.FromStream(ms); //############################################################## ms.Position = 0; return ms; 

by andrewsmd87 via /r/csharp

Leave a Reply