[Question] Hi-def image is too small when viewed in WebChat. How to open a popup or new tab by clicking it?
Bot Info
SDK Platform: .NET Active Channels: Web Chat Deployment Environment: Azure Bot Service
Issue Description
Image too small. Impossible to see the content.
Code Example
var replyMessage = context.MakeMessage();
Attachment attachment = new Attachment();
attachment.ContentType = "image/png";
var imageData = Convert.ToBase64String(File.ReadAllBytes(HttpContext.Current.Server.MapPath($"~/images/{path}")));
attachment.ContentUrl = $"data:image/png;base64,{imageData}";
replyMessage.Attachments.Add(attachment);
await context.PostAsync(replyMessage);
Expected Behavior
Open a popup or a new tab with the image, after a user click.
Actual Results

The image is too small and user cannot understand the content of it. Is there any way to open the image in a popup or newtab after the click of the user?
@luisnatividade Put your image in a Hero Card with a button that links to the full resolution image URL.
As he said using a hero card you can accomplish this. Here is a code example:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
IMessageActivity reply = context.MakeMessage();
HeroCard heroCard = new HeroCard()
{
Images = new List<CardImage>
{
new CardImage(url: $"https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")
},
Tap = new CardAction()
{
Value = $"https://www.google.com",
Type = "openUrl",
}
};
reply.Attachments = new List<Attachment>
{
heroCard.ToAttachment()
};
await context.PostAsync(reply);
}
@nwhitmont and @JasonSowers Thank you. Does it work with local images?
It should work with local ones as well. I do not have an example of one already coded up unfortunately
I just tried it out and the following code worked for me:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var reply2 = await result as Activity;
Activity reply = reply2.CreateReply();
string base64String;
string image64;
try
{
using (Image image = Image.FromFile(@"C:\source\bomb300.png"))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
// Convert byte[] to Base64 String
base64String = Convert.ToBase64String(imageBytes);
}
}
image64 = "data:image/png;base64," + base64String;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
HeroCard heroCard = new HeroCard()
{
Images = new List<CardImage>
{
new CardImage(
url: image64)
},
Tap = new CardAction()
{
Value = $"https://www.google.com",
Type = "openUrl",
}
};
reply.Attachments = new List<Attachment>
{
heroCard.ToAttachment()
};
await context.PostAsync(reply);
}
Closing this issue as it should be resolved for you now. Feel free to continue the conversation if needed.
@JasonSowers Thanks for the answer! The only thing is that I dont't want to open an url when clicking in the image. I want to open a tab with the image. Is it possible with local images?
I want to do this because since the width of the chatbot is small it's difficult to see clearly the image.
Thanks in advance.
I missed that part in my example. The easiest way to do this would be to add the picture to your project and call it as an endpoint like Value = @"http://localhost:3979/bomb300.png", here is this code again with minor changes that should be what you need:
var reply2 = await result as Activity;
Activity reply = reply2.CreateReply();
string base64String;
string image64;
try
{
using (Image image = Image.FromFile(@"C:\Users\v-jassow\Documents\Visual Studio 2017\Projects\Bot Application6\Bot Application6\bomb300.png"))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
// Convert byte[] to Base64 String
base64String = Convert.ToBase64String(imageBytes);
}
}
image64 = "data:image/png;base64," + base64String;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
HeroCard heroCard = new HeroCard()
{
Images = new List<CardImage>
{
new CardImage(
url: image64)
},
Tap = new CardAction()
{
Value = @"http://localhost:3979/bomb300.png",
Type = "openUrl",
}
};
reply.Attachments = new List<Attachment>
{
heroCard.ToAttachment()
};
await context.PostAsync(reply);
@JasonSowers I'm working with the App Service Editor on Azure Portal and I have the image on "WWWROOT" folder. The way I get the image is using HttpContext.Current.Server.MapPath($"~/{imageName}"). I'm testing the chatbot using the webchat channel. So I think using the localhost won't work. The code of the previous answer works, except the line: Value = @"http://localhost:3979/bomb300.png". I tried different ways but sill can't make it to work...
I will have to try this out myself in azure bot service, I will try to get to this today.
@JasonSowers Any update? I tried different ways today but I'm still stuck in the problem...
I will look today
I want to make sure I recreate this properly is this a web app bot in azure?
@JasonSowers yes it is.
@luisnatividade I have successfully accomplished what you need, Here is the project https://github.com/JasonSowers/HeroCardOpenUrl
Thanks @JasonSowers it works perfectly in my project. I was missing the Uri...
Glad it works for you now.