我在.Net核心中创建了一个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)的图像?
发布于 2019-02-07 16:41:40
直接保存你得到的内容:
using (var fs = new FileStream(filePath, FileMode.Create))
fs.Write(data, 0, data.Length);https://stackoverflow.com/questions/54557840
复制相似问题