Tôi đang cố gắng đoạn mã sau vào đầu ra một hình ảnh từ một api web asp.net, nhưng chiều dài cơ thể phản ứng luôn luôn là 0.hình ảnh đầu ra sử dụng web api HttpResponseMessage
public HttpResponseMessage GetImage()
{
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StreamContent(new FileStream(@"path to image"));
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
}
Bất cứ lời khuyên?
CÔNG TRÌNH:
[HttpGet]
public HttpResponseMessage Resize(string source, int width, int height)
{
HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
// Photo.Resize is a static method to resize the image
Image image = Photo.Resize(Image.FromFile(@"d:\path\" + source), width, height);
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Jpeg);
httpResponseMessage.Content = new ByteArrayContent(memoryStream.ToArray());
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
httpResponseMessage.StatusCode = HttpStatusCode.OK;
return httpResponseMessage;
}
Không hoàn toàn chắc chắn nếu tôi có bạn - nhưng bạn có thể kiểm tra [** cách viết hình ảnh tới outputStream **] (http://stackoverflow.com/questions/5629251/c-sharp-outputting-image-to -response-output-stream-giving-gdi-error) –
Tôi không nhận được lỗi, tôi chỉ không nhận được gì cả. – lolol
bạn đang nhận lại mã trạng thái nào? –