我在 .Net Core 中创建了一个 Web 服务。此服务返回像素格式为 8pp 索引的图像 png:
using (Bitmap bmp = new Bitmap(img.width, img.height, PixelFormat.Format8bppIndexed))
{
using (MemoryStream ms = new MemoryStream())
{
bmp.Save(ms, imgFormat);
return new FileContentResult(ms.ToArray(), $"image/png");
}
}
我想测试这个服务,所以我用这段代码创建了一个 C# 测试:
Task<HttpResponseMessage> responseTask = client.PostAsync(url, content);
responseTask.Wait();
var response = responseTask.Result;
HttpContent ct = response.Content;
byte[] data = await ct.ReadAsByteArrayAsync();
using (MemoryStream m = new MemoryStream(data))
{
Bitmap img = new Bitmap(m);
img.Save(filePath, ImageFormat.Png);
}
但位图img
是 Format32bppArgb。如何以原始格式 (Format8bppIndexed) 获取我的图像?