in C #, you can use the PictureBox control to render an image, an image resource can come from a file, or it can be a bitmap object that exists in memory. You can display a local image file or a picture from a network, or from an image in a project file.
Loads an image file from a URI.
Either the load (synchronous load) or the LoadAsync (asynchronous load) method is called to load the image from the specified URI. If the image is large, it can be loaded asynchronously using the LoadAsync method, which ensures that the user interface is able to respond to user actions and that there is a deadlock phenomenon
If you use asynchronous loading, you can also handle the Loadprogresschanged event, which is raised when the progress of the load changes. The LoadCompleted event occurs when an image is loaded, changed, or canceled.
1. Create a project
2. Drag the TextBox from the Toolbox as the input to the picture path, button as the confirmation load buttons, PictureBox as the picture loading container
Layout
3. Add Key events
Private voidButton1_Click (Objectsender, EventArgs e) { //determine if the Txturi character is empty if(string. Isnullorwhitespace (Txturi.text)) {MessageBox.Show ("Please enter an image URI","Tips", MessageBoxButtons.OK, messageboxicon.warning); return; } //Close the Load buttonButton1. Enabled =false; //loading images asynchronously, loading Txturi imagesPicturebox1.loadasync (Txturi.text); }
4. We can add, loadprogersschanged (Load Progress) and LoadComplete (load error) events because we are using asynchronous load mode
Private voidPicturebox1_loadprogresschanged (Objectsender, ProgressChangedEventArgs e) { //Show Progress This. Lblmsg.text =string. Format ("Current progress: {0}.", E.progresspercentage); } Private voidPicturebox1_loadcompleted (Objectsender, AsyncCompletedEventArgs e) { //loading error handling Events if(E.error! =NULL) {Lblmsg.text="error message:"+E.error.message; return; } //If you cancel if(e.cancelled) {Lblmsg.text="The operation was canceled. "; } Else{Lblmsg.text="loading is complete."; } button1. Enabled=true; }
Run the program, enter the image URI in the text box, either a local image full path or a network picture address.
C # Image Rendering control PictureBox