how to show media in pictureBox?

64 Views Asked by At

I just want to get msg from (any) channel and if it have media (check by flag) show it in pictureBox. howto show media in pictureBox from await client.DownloadFileAsync(photo, fileStream); or another functions with .Media field?

upd: the correct question is: how to show *.jpg file from DownloadFileAsync without saving to disk and work only with memory?

1

There are 1 best solutions below

1
Wizou On

You can download the photo directly to a MemoryStream.

Remember to reset stream position to the beginning of file before using the downloaded content

    var memStream = new MemoryStream();
    await client.DownloadFileAsync(photo, memStream);
    memStream.Position = 0;
    pictureBox.Image = Image.FromStream(memStream);

Note: in order to use await in your code, you must make your method async (for example async void)