tgbot-cpp icon indicating copy to clipboard operation
tgbot-cpp copied to clipboard

Poor quality of the downloaded picture

Open papazloynt opened this issue 3 years ago • 4 comments

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.

  1. 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?
  2. 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;
            }
        });

papazloynt avatar Dec 08 '21 19:12 papazloynt

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)

papazloynt avatar Dec 09 '21 03:12 papazloynt

what processing?

JellyBrick avatar Dec 09 '21 08:12 JellyBrick

My task is to save pictures to my computer that people send to my bot.

papazloynt avatar Dec 09 '21 11:12 papazloynt

auto file_id = message->photo[2]->fileId it will resolve your problem ----^ if it not resolved yet

drewaaaaa avatar Jun 17 '22 01:06 drewaaaaa