I am using Bot Application Framework of C# to build a skype bot. I do some processing on image and then send it back to user in carousel of hero cards.
I am following the constraints of the hero card, I am resizing image so that it's resolution is below 1024*1024, it's type is png/jpg and it's size is below 1MB. Also the link to the image is HTTPS://
Images loads in the web chat of https://dev.botframework.com every time, but when I use it on skype PC or Android it loads rarely.
This is how I am making the carousel.
var carousel = context.MakeMessage();
carousel.AttachmentLayout = AttachmentLayoutTypes.Carousel;
carousel.Attachments.Add(GetHeroCard(null, null, "Share this!", new CardImage(url: imageUrl, alt: imageUrl, tap: new CardAction(ActionTypes.ShowImage))));
This is how I am encoding Bitmap object to the png/jpeg format byte array to upload on the blob, from where I get the HTTPS link to the image.
public static byte[] BitmapEncode2Byte(Bitmap bitmap, ImageFormat format)
{
MemoryStream stream = new MemoryStream();
EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
bitmap.Save(stream, GetEncoder(ImageFormat.Png), encoderParameters);
return stream.ToArray();
}
public static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
Thanks in Advance!