private async Task ReplyImagemapAsync(string replyToken, string messageId, string blobDirectoryName) { var imageStream = await MessagingClient.GetContentStreamAsync(messageId); var image = System.Drawing.Image.FromStream(imageStream); using (var g = Graphics.FromImage(image)) { g.DrawLine(Pens.Red, image.Width / 2, 0, image.Width / 2, image.Height); g.DrawLine(Pens.Red, 0, image.Height / 2, image.Width, image.Height / 2); } var uri = await UploadImageAsync(1040); await UploadImageAsync(700); await UploadImageAsync(460); await UploadImageAsync(300); await UploadImageAsync(240); var imageSize = new ImagemapSize(1024, (int)(1040 * (double)image.Height / image.Width)); var areaWidth = imageSize.Width / 2; var areaHeight = imageSize.Height / 2; Video video = null; var videoUrl = BlobStorage.ListBlobUri(blobDirectoryName).FirstOrDefault(x => x.ToString().EndsWith("video.mp4")); if (videoUrl != null) { video = new Video(videoUrl.ToString(), videoUrl.ToString().Replace("video.mp4", "300"), new ImagemapArea(areaWidth / 2, areaHeight / 2, areaWidth, areaHeight), new ExternalLink("https://google.com", "google")); } var imagemapMessage = new ImagemapMessage(uri.ToString().Replace("/1040", ""), "Sample Imagemap", imageSize, new IImagemapAction[] { new MessageImagemapAction(new ImagemapArea(0, 0, areaWidth, areaHeight), "Area Top-Left"), new MessageImagemapAction(new ImagemapArea(areaWidth, 0, areaWidth, areaHeight), "Area Top-Right"), new MessageImagemapAction(new ImagemapArea(0, areaHeight, areaWidth, areaHeight), "Area Bottom-Left"), new MessageImagemapAction(new ImagemapArea(areaWidth, areaHeight, areaWidth, areaHeight), "Area Bottom-Right"), }, video: video); await MessagingClient.ReplyMessageAsync(replyToken, new[] { imagemapMessage }); async Task <Uri> UploadImageAsync(int baseSize) { var img = image.GetThumbnailImage(baseSize, image.Height * baseSize / image.Width, () => false, IntPtr.Zero); return(await BlobStorage.UploadImageAsync(img, blobDirectoryName, baseSize.ToString())); } }
private async Task EchoImageAsync(string replyToken, string messageId, string blobDirectoryName) { var imageName = messageId + ".jpeg"; var previewImageName = messageId + "_preview.jpeg"; var imageStream = await MessagingClient.GetContentStreamAsync(messageId); var image = Image.FromStream(imageStream); var previewImage = image.GetThumbnailImage((int)(image.Width * 0.25), (int)(image.Height * 0.25), () => false, IntPtr.Zero); var blobImagePath = await BlobStorage.UploadImageAsync(image, blobDirectoryName, imageName); var blobPreviewPath = await BlobStorage.UploadImageAsync(previewImage, blobDirectoryName, previewImageName); await MessagingClient.ReplyMessageAsync(replyToken, new[] { new ImageMessage(blobImagePath.ToString(), blobPreviewPath.ToString()) }); }
private async Task UploadImageAsync(string replyToken, string messageId, string blobDirectoryName) { var imageStream = await MessagingClient.GetContentStreamAsync(messageId); var image = System.Drawing.Image.FromStream(imageStream); var imageCount = BlobStorage.ListBlobUri(blobDirectoryName).Count(); if (imageCount == 5) { await BlobStorage.DeleteDirectoryAsync(blobDirectoryName); imageCount = 0; } await BlobStorage.UploadImageAsync(image, blobDirectoryName, (imageCount + 1) + ".jpeg"); await MessagingClient.ReplyMessageAsync(replyToken, $"Image uploaded ({imageCount + 1})."); }
private async Task ReplyImagemapAsync(string replyToken, string messageId, string blobDirectoryName) { var imageStream = await MessagingClient.GetContentStreamAsync(messageId); var image = Image.FromStream(imageStream); using (var g = Graphics.FromImage(image)) { g.DrawLine(Pens.Red, image.Width / 2, 0, image.Width / 2, image.Height); g.DrawLine(Pens.Red, 0, image.Height / 2, image.Width, image.Height / 2); } var uri = await UploadImageAsync(1040); await UploadImageAsync(700); await UploadImageAsync(460); await UploadImageAsync(300); await UploadImageAsync(240); var imageSize = new ImagemapSize(1024, (int)(1040 * (double)image.Height / image.Width)); var areaWidth = imageSize.Width / 2; var areaHeight = imageSize.Height / 2; var imagemapMessage = new ImagemapMessage(uri.ToString().Replace("/1040", ""), "Sample Imagemap", imageSize, new IImagemapAction[] { new MessageImagemapAction(new ImagemapArea(0, 0, areaWidth, areaHeight), "Area Top-Left"), new MessageImagemapAction(new ImagemapArea(areaWidth, 0, areaWidth, areaHeight), "Area Top-Right"), new MessageImagemapAction(new ImagemapArea(0, areaHeight, areaWidth, areaHeight), "Area Bottom-Left"), new MessageImagemapAction(new ImagemapArea(areaWidth, areaHeight, areaWidth, areaHeight), "Area Bottom-Right"), }); await MessagingClient.ReplyMessageAsync(replyToken, new[] { imagemapMessage }); async Task <Uri> UploadImageAsync(int baseSize) { var img = image.GetThumbnailImage(baseSize, image.Height * baseSize / image.Width, () => false, IntPtr.Zero); return(await BlobStorage.UploadImageAsync(img, blobDirectoryName + "/" + messageId, baseSize.ToString())); } }
protected override async Task OnMessageAsync(MessageEvent ev) { var msg = ev.Message as TextEventMessage; if (msg == null) { return; } switch (msg.Text) { case "Rectangle-Cover": await ReplyButtonsTemplateMessageAsync(ImageAspectRatioType.Rectangle, ImageSizeType.Cover); break; case "Square-Contain": await ReplyButtonsTemplateMessageAsync(ImageAspectRatioType.Square, ImageSizeType.Contain); break; case "Square-Cover": await ReplyButtonsTemplateMessageAsync(ImageAspectRatioType.Square, ImageSizeType.Cover); break; case "Rectangle-Contein": default: await ReplyButtonsTemplateMessageAsync(ImageAspectRatioType.Rectangle, ImageSizeType.Contain); break; } async Task ReplyButtonsTemplateMessageAsync(ImageAspectRatioType imageAspectRatio, ImageSizeType imageSize) { var imageUri = BlobStorage.ListBlobUri(blobDirectoryName).FirstOrDefault(uri => uri.ToString().EndsWith(imageName)); if (imageUri == null) { imageUri = await BlobStorage.UploadImageAsync(Properties.Resources.sample_image, blobDirectoryName, imageName); } var actions = new[] { new MessageTemplateAction("Rectangle-Contain", "Rectangle-Contain"), new MessageTemplateAction("Rectangle-Cover", "Rectangle-Cover"), new MessageTemplateAction("Square-Contain", "Square-Contain"), new MessageTemplateAction("Square-Cover", "Square-Cover") }; var templateMessage = new TemplateMessage("ButtonsTemplate", new ButtonsTemplate( imageAspectRatio.ToString() + "-" + imageSize.ToString(), imageUri.ToString(), "Test of thumbnail image settings", actions, imageAspectRatio, imageSize, imageBackgroundColor: "#FF0000")); await MessagingClient.ReplyMessageAsync(ev.ReplyToken, new[] { templateMessage }); } }