发送图像而不是链接 [英] Send an image rather than a link

查看:120
本文介绍了发送图像而不是链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Microsoft Bot Framework与Cognitive Services结合使用,以从用户通过bot上传的源图像生成图像.我正在使用C#.

I'm using the Microsoft Bot Framework with Cognitive Services to generate images from a source image that the user uploads via the bot. I'm using C#.

Cognitive Services API返回表示已处理图像的byte[]Stream.

The Cognitive Services API returns a byte[] or a Stream representing the treated image.

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

How can I send that image directly to my user? All the docs and samples seem to point to me having to host the image as a publically addressable URL and send a link. I can do this but I'd rather not.

有人像Caption Bot一样知道如何简单地返回图像吗?

Does anyone know how to simple return the image, kind of like the Caption Bot does?

推荐答案

您应该可以使用以下内容:

You should be able to use something like this:

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);

这篇关于发送图像而不是链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆