[C # development skills series] C # How to Implement Image Viewer

Source: Internet
Author: User

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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.