国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

winfrom-OpenFileDialog選擇圖片并設定大小

2019-11-10 23:31:29
字體:
來源:轉載
供稿:網友

using System;using System.Drawing;using System.Windows.Forms;namespace WindowsFormsapplication2{    public partial class selectimg : Form    {        public selectimg()        {            InitializeComponent();            this.pictureBox1.BorderStyle = BorderStyle.FixedSingle;            this.openFileDialog1.Filter = "圖片|*.jpg;*.png";        }        PRivate void button1_Click(object sender, EventArgs e)        {            if (openFileDialog1.ShowDialog() == DialogResult.OK)            {                Image fromImage = Image.FromFile(this.openFileDialog1.FileName);                fromImage = fromImage.AdjImageToFitSize(pictureBox1.Width, pictureBox1.Height); //350                this.pictureBox1.Image = fromImage;            }        }        //...    }    internal static class ImgHelp    {        /// <summary>        /// 獲取等比例縮放的圖片(高寬不一致時獲取最中間部分的圖片)        /// </summary>        public static Image AdjImageToFitSize(this Image fromImage, int width, int height)        {            Bitmap bitmap = new Bitmap(width, height);            Graphics graphics = Graphics.FromImage(bitmap);            Point[] destPoints = new Point[] {                new Point(0, 0),                new Point(width, 0),                new Point(0, height)            };            Rectangle rect = GetImageRectangle(fromImage.Width, fromImage.Height);            graphics.DrawImage(fromImage, destPoints, rect, GraphicsUnit.Pixel);            Image image = Image.FromHbitmap(bitmap.GetHbitmap());            bitmap.Dispose();            graphics.Dispose();            return image;        }        /// <summary>        /// 居中位置獲取        /// </summary>        private static Rectangle GetImageRectangle(int w, int h)        {            int x = 0;            int y = 0;            if (h > w)            {                h = w;                y = (h - w) / 2;            }            else            {                w = h;                x = (w - h) / 2;            }            return new Rectangle(x, y, w, h);        }    }}


上一篇:va_list 詳解

下一篇:Spring MVC--1.helloworld

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 红安县| 西峡县| 桦南县| 博乐市| 竹北市| 阿勒泰市| 仁布县| 富阳市| 弥勒县| 澄城县| 古浪县| 万宁市| 老河口市| 曲沃县| 江口县| 宣城市| 滕州市| 山阴县| 祁东县| 咸阳市| 体育| 广德县| 利辛县| 宁德市| 古丈县| 万源市| 翁源县| 徐州市| 津南区| 康马县| 呼玛县| 门源| 凤翔县| 淮安市| 平度市| 合川市| 维西| 民和| 宣威市| 东兴市| 宾阳县|