Summary of this topic
- I. Introduction
- II. Implementation ideas
- Iii. Implementation results
- Iv. Summary
I. Introduction
Recently, I have seen some friends in the MSDN and CSDN forums asking me how to use C # To implement a function similar to the image Viewer provided by Windows (and of course how to rotate images )., how to Use buttons to change image functions), so in order to help you better solve such problems, therefore, this article will briefly introduce how to use C # To implement the function of an image viewer. The functions saved by this tool include:
II. Implementation ideas2.1 Implementation of the image rotation browsing Function
- Step 1: Obtain the set of all images in the directory.Directory. GetFiles ()To obtain all the files in the directory, and then filter the set to filter out the files that are images. The Code uses the extension to filter
- Step 2. After obtaining all the image sets, you need to change the index of the set to achieve the previous and next functions.
- Step 3: Consider the last or first image, and then click the next or previous image to rotate it into the first or last one.
The idea is the above. With the above idea, let's take a look at the specific code to compare and understand:
// Step 1List <> GetImgCollection ([] imgarray = result = imgstring. EndsWith (, StringComparison. OrdinalIgnoreCase) |, StringComparison. OrdinalIgnoreCase) | // Step 2GetIndex (index = (I =; I
The above code implements the first function point. The following explains how to implement the second function point-image rotation:
For the Image Viewer that comes with Windows, the rotation angle can only Rotate 90 degrees clockwise or 90 degrees clockwise. This function can be very simple to achieve, you only need to use Image. RotateFlip (RotateFlipType)The method can be done. Some friends also want to rotate the image at any angle. The source code of this problem also has specific implementation. You can download the source code from the end of the article to view it, here we will not post the specific code. Next we will look at how to implement the Code for rotating the Image Viewer that comes with Windows:
btnRotate_Click(=== btncounterclockwiseRotate_Click(=== }
You can save the image by using the following code:
Form1_FormClosed( (imgPath == || isRotate ==
Iii. Implementation results
I have already introduced the idea of implementing this program. Can you wait to see what the custom image Viewer looks like? The following uses an animation to show the running effect of a program more vividly: