justdmitry / NetTelegramBotApi

C# client library for building Telegram bot
MIT License
74 stars 28 forks source link

Send bitmap as photo #37

Closed shdehnavi closed 7 years ago

shdehnavi commented 7 years ago

hi

i want to send bitmap variable type as a photo by NetTelegramBotApi: Bitmap bmp;

using (var photoData = Assembly.GetExecutingAssembly().GetManifestResourceStream("InstagramPuzzleBot.Resources.sample.png")) i want to send bitmap contents, what should i write instead of : Assembly.GetExecutingAssembly().GetManifestResourceStream("NetTelegramBotApi.t_logo.png ?

i used this bug i got error:

                                Stream mms = new MemoryStream();
                                Bitmap bmp = makePuzzle(address, ID); //function with bitmap return type
                                bmp.Save(mms, System.Drawing.Imaging.ImageFormat.Bmp);

                                var reqAction = new SendChatAction(update.Message.Chat.Id, "upload_photo");
                                bot.MakeRequestAsync(reqAction).Wait();
                                System.Threading.Thread.Sleep(500);
                                using (var photoData = mms)
                                {
                                    var req = new SendPhoto(update.Message.Chat.Id, new FileToSend(photoData, "sample.png"))
                                    {
                                        Caption = "samplephoto"
                                    };
                                    var msg = bot.MakeRequestAsync(req).Result;
                                    SamplePhotoID = msg.Photo.Last().FileId;
                                }
justdmitry commented 7 years ago

It depends of file location. You can read it with File.OpenRead or use MemoryStream as a source - there are a lot of choices. You should provide Stream to read file from.

About your sample - you forgot to add error text you receive,. BTW I think you should rewind mms back to start with mms.Position = 0 after bmp.Save

shdehnavi commented 7 years ago

mms.Position = 0

solved , thanq