首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从具有正确像素格式的流中创建图像

从具有正确像素格式的流中创建图像
EN

Stack Overflow用户
提问于 2019-02-07 00:07:45
回答 1查看 272关注 0票数 0

我在.Net核心中创建了一个web服务。此服务返回像素格式为8pp索引的图像png:

代码语言:javascript
复制
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#测试:

代码语言:javascript
复制
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)的图像?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-07 16:41:40

直接保存你得到的内容:

代码语言:javascript
复制
using (var fs = new FileStream(filePath, FileMode.Create))
    fs.Write(data, 0, data.Length);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54557840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档