Botframework 发送图像而不是链接

Botframework 发送图像而不是链接,botframework,microsoft-cognitive,skype-bots,Botframework,Microsoft Cognitive,Skype Bots,我使用MicrosoftBot框架和认知服务从用户通过Bot上传的源图像生成图像。我用的是C 认知服务API返回表示已处理图像的字节[]或流 如何将该图像直接发送给我的用户?所有的文档和示例似乎都指向我,我必须将图像作为一个可公开寻址的URL托管,并发送一个链接。我可以这样做,但我宁愿不这样做 有人知道如何像字幕机器人那样简单地返回图像吗?您应该能够使用以下内容: var message = activity.CreateReply(""); message.Type = "message";

我使用MicrosoftBot框架和认知服务从用户通过Bot上传的源图像生成图像。我用的是C

认知服务API返回表示已处理图像的
字节[]

如何将该图像直接发送给我的用户?所有的文档和示例似乎都指向我,我必须将图像作为一个可公开寻址的URL托管,并发送一个链接。我可以这样做,但我宁愿不这样做


有人知道如何像字幕机器人那样简单地返回图像吗?

您应该能够使用以下内容:

var message = activity.CreateReply("");
message.Type = "message";

message.Attachments = new List<Attachment>();
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData("https://placeholdit.imgix.net/~text?txtsize=35&txt=image-data&w=120&h=120");
string url = "data:image/png;base64," + Convert.ToBase64String(imageBytes)
message.Attachments.Add(new Attachment { ContentUrl = url, ContentType = "image/png" });
await _client.Conversations.ReplyToActivityAsync(message);
var message=activity.CreateReply(“”);
message.Type=“message”;
message.Attachments=新列表();
var webClient=新的webClient();
byte[]imageBytes=webClient.DownloadData(“https://placeholdit.imgix.net/~text?txtsize=35&txt=图像数据&w=120&h=120“;
string url=“data:image/png;base64,”+Convert.ToBase64String(imageBytes)
message.Attachments.Add(新附件{ContentUrl=url,ContentType=“image/png”});
wait_client.Conversations.ReplyToActivityAsync(消息);

HTML图像元素的图像源可以是直接包含图像的数据URI,而不是用于下载图像的URL。以下重载函数将获取任何有效图像,并将其编码为JPEG数据URI字符串,该字符串可直接提供给HTML元素的src属性以显示图像。如果您提前知道返回的图像的格式,那么您可能可以通过不将图像重新编码为JPEG来节省一些处理,只返回编码为base 64并带有适当图像数据URI前缀的图像

    public string ImageToBase64(System.IO.Stream stream)
{
    // Create bitmap from stream
    using (System.Drawing.Bitmap bitmap = System.Drawing.Bitmap.FromStream(stream) as System.Drawing.Bitmap)
    {
        // Save to memory stream as jpeg to set known format.  Could also use PNG with changes to bitmap save 
        // and returned data prefix below
        byte[] outputBytes = null;
        using (System.IO.MemoryStream outputStream = new System.IO.MemoryStream())
        {
            bitmap.Save(outputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            outputBytes = outputStream.ToArray();
        }

        // Encoded image byte array and prepend proper prefix for image data. Result can be used as HTML image source directly
        string output = string.Format("data:image/jpeg;base64,{0}", Convert.ToBase64String(outputBytes));

        return output;
    }
}

public string ImageToBase64(byte[] bytes)
{
    using (System.IO.MemoryStream inputStream = new System.IO.MemoryStream())
    {
        inputStream.Write(bytes, 0, bytes.Length);
        return ImageToBase64(inputStream);
    }
}

这是在Web应用程序Bot中工作的,它在Microsoft团队中抛出错误…如果有人解释这句话的含义将是非常好的--string url=“data:image/png;base64,”+Convert.ToBase64String(imageBytes)这是如何解决OP提出的问题的。