In C #, how does one scale and load pictures in a proportional manner in picturebox?

Source: Internet
Author: User
Method 1: If the aspect ratio of the image to be loaded is not too unbalanced, you can change the sizemode attribute of picturebox to pictureboxsizemode. stretchimage. In this way, the image loaded into the picturebox will be filled with the entire picturebox. However, this method is not very good when the aspect ratio of an image is large. You can select method 2. Method 2: see; http://www.cnblogs.com/fengzanfeng/articles/1339107.html openfiledialog ofdpic = new openfiledialog (); ofdpic. filter = "JPG (*. JPG ;*. JPEG); GIF file (*. GIF) | *. JPG ;*. JPEG ;*. GIF "; ofdpic. filterindex = 1; ofdpic. filename = ""; if (ofdpic. showdialog () = dialogresult. OK) {string spicpaht = ofdpic. filename. tostring (); bitmap BMP Ic = new Bitmap (spicpaht); point ptloction = new point (bmp ic. size); If (ptloction. x> mypicbox. size. width | ptloction. y> mypicbox. size. height) {// call method of the Photo Frame // pcbpic. dock = dockstyle. fill; // fill the photo box with a portrait, and the proportion of the photo watermark is mypicbox. sizemode = pictureboxsizemode. zoom;} else {// consumer image in the portrait box mypicbox. sizemode = pictureboxsizemode. centerimage;} // loadasync: Non-synchronous ingress inbound image like mypicbox. loadasync (spicpaht );}
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.