你好,我正在编写一个聊天机器人,我需要能够在聊天中发送图像。它们只是小图标。 我尝试调整“处理附件”示例(https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/15.handling-attachments/Bots/AttachmentsBot.cs)
中的代码但是它会自动调整小图标的大小以适合更大的框架。我不确定为什么...
这是我使用的代码:
var reply = MessageFactory.Text("This is an inline attachment.");
reply.Attachments = new List<Attachment>() { GetInlineAttachment() };
await stepContext.Context.SendactivityAsync(reply,cancellationToken);
private static Attachment GetInlineAttachment()
{
var imagePath = Path.Combine(Environment.CurrentDirectory,@"Resources\uc2icon.png");
var imageData = Convert.ToBase64String(File.ReadAllBytes(imagePath));
return new Attachment
{
Name = @"Resources\architecture-resize.png",ContentType = "image/png",ContentUrl = $"data:image/png;base64,{imageData}",};
}
我对C#还是相当陌生,而且还对代码进行了一般性的介绍,我非常感谢!谢谢