I am making an MVC controller method call. The return type is FileStreamResult. In this method, I create an image as an array of bytes. I create a MemoryStream by passing an array of bytes in the constructor. Then I return a new FileStreamResult object with a memory stream object and "image / png" in the constructor, since my image is PNG.
public FileStreamResult GetImage()
{
ImageModel im = new ImageModel();
var image = im.GetImageInByteArray();
var stream = new MemoryStream(image);
return new FileStreamResult(stream, "image/png");
}
Now that I get a stream of requests from this call, I just use the following method to convert the stream string to an array of bytes to view the image. However, after that, everything will end with more than 100 positions in my byte array than when I return from the MVC controller method call.
public static byte[] ConvertStringToBytes(string input)
{
MemoryStream stream = new MemoryStream();
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(input);
writer.Flush();
}
return stream.ToArray();
}
, "GetImageInByteArray()" "byte [256]".
MVC, , , "byte [398]";
- -, GetImage(), , ?
, .
.
?