Extract images from the network and display them sequentially

  • I want to create a scrollable list of images retrieved from the web and let the user click on it. How do I go about doing this in WinForms / C #? Is it possible to add an image control / control to the listBox?

  • I tried adding the list of images to the UserControl with the AutoScroll parameter to true, which will give me the feeling that you are using a listBox, is this the correct approach?

  • I also tried setting the ImageLocation of the pictureBox to the Image URI and then loading Load () to load the image, it did work, however my form freezes! How can I update each of the image boxes in a sequential manner without freezing my form?

Thanks, Azlam

0


source to share


2 answers


I'll answer your third question first, because the only one that I REALLY know the answer with. The image field has a LoadAsync () method that will load the image on a separate thread and not hang your application.

As for other questions, I too would most likely start with a custom control and put the images there. The only thing I can suggest is to first create a custom control that has a window with a picture, and perhaps a multi-line text box or richtextbox next to it. Disable the border in the text box and slightly lower it around the entire control. This will allow you to display the image with text next to it. Then your actual final control will simply be a collection of these controls, with the ability to add them as needed.



- my 2 cents ...

+1


source


Do you mind scrolling vertically?

I would start with a DataGridView control as a base and create the following implementation:

1) Create custom column and celltype obtained from DataGridViewImageColumn. You can name them "CronosNetImageColumn", "CronosNetImageCell".

2) Create a class "CronosImageDetails" to store honeycomb data (including properties for displaying text and image url). This will be passed as the value for each cell. Example:

ImageGrid.Rows.Add (new CronosImageDetails {DisplayText = "Day at the Beach", ImageURL = "http: //...beach.jpg"});

3) Overlap the Paint () cell to use the WebClient to get the image and use e.Graphics.DrawImage (ImageObtainedFromWebClient) to draw the image into the cell. You can use e.Graphics.DrawString ((CronosImageDetails) value.DisplayText, ...) to overlay text into a cell.

This quick solution will provide you with a scrolling image that only loads images if the user scrolls through the list and provides a solid foundation for improvement.



We recommend further optimizations:

A) Create a bitmap backguffer and graphics to paint the cell data.

B) Setup Paint () to just paint the backbuffer instead of doing the job to get the image

C) Create a new Cell LoadImage () method that creates a new thread that loads the image and draws it to the back buffer.

D). Paint () (or a separate helper thread) tracks the direction and acceleration of the scrolling and estimates which cells need to be preloaded. Trigger LoadImage () on these cells.

E) Initialize the back buffer of each cell with the boot image.

F) Track and use empirical data from image load times to determine which cells need to be preloaded.

0


source







All Articles