tgbot-cpp
tgbot-cpp copied to clipboard
Poor quality of the downloaded picture
Hi everybody! I am trying to download a picture that is sent to a bot in a chat, here is my implementation:
I understand that it is not the best, and therefore I am turning to you.
- What is the best way to organize receiving only a picture, and not any event and then checking it for the emptiness of an array of photos?
- Why is the image being downloaded of low quality? How can I improve its quality?
bot.getEvents().onAnyMessage([this](Message::Ptr message) {
if (!message->photo.empty()) {
auto file_id = message->photo[0]->fileId;
auto file_info = bot.getApi().getFile(file_id);
auto downloaded = bot.getApi().downloadFile(file_info->filePath);
std::ofstream out("image.jpg", std::ios::binary);
out << downloaded;
}
});
To get the image at its maximum size, I changed the receive photo size to the maximum size, like here:
auto file_info = bot.getApi().getFile(message->photo[message->photo.size() - 1]->fileId);
But the question of how to do the processing of a photo is still relevant)
what processing?
My task is to save pictures to my computer that people send to my bot.
auto file_id = message->photo[2]->fileId it will resolve your problem ----^ if it not resolved yet