最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#中調(diào)整圖像大小的步驟詳解

 更新時(shí)間:2021年05月08日 14:33:42   作者:E-iceblue  
這篇文章主要介紹了C#中調(diào)整圖像大小的步驟詳解,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

在本篇文章中,我將介紹如何在C#中來(lái)調(diào)整你想要的圖像大小。要實(shí)現(xiàn)這一目標(biāo),我們可以采取以下幾個(gè)步驟:

1.首先要獲取你想要調(diào)整大小的圖像:

string path = Server.MapPath("~/Images");
System.Drawing.Image img = System.Drawing.Image.FromFile(string.Concat(path,"/3904.jpg"));

2.將圖像轉(zhuǎn)換為Bitmap:

Bitmap b = new Bitmap(img);

3.創(chuàng)建一個(gè)調(diào)整圖像大小的方法:

private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
{
    //獲取圖片寬度
    int sourceWidth = imgToResize.Width;
    //獲取圖片高度
    int sourceHeight = imgToResize.Height;
  
    float nPercent = 0;
    float nPercentW = 0;
    float nPercentH = 0;
    //計(jì)算寬度的縮放比例
    nPercentW = ((float)size.Width / (float)sourceWidth);
    //計(jì)算高度的縮放比例
    nPercentH = ((float)size.Height / (float)sourceHeight);      
  
    if (nPercentH < nPercentW)
        nPercent = nPercentH;
    else
     nPercent = nPercentW;
     //期望的寬度
     int destWidth = (int)(sourceWidth * nPercent);
     //期望的高度
     int destHeight = (int)(sourceHeight * nPercent);
  
     Bitmap b = new Bitmap(destWidth, destHeight);
     Graphics g = Graphics.FromImage((System.Drawing.Image)b);
     g.InterpolationMode = InterpolationMode.HighQualityBicubic;
     //繪制圖像
     g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
     g.Dispose();
     return (System.Drawing.Image)b;
}

 在上面的方法中,我們獲取了位圖圖像,然后繪制了不同尺寸的圖像(這里繪制出的圖像是基于指定的縱橫比)

4.調(diào)用上述方法,得到調(diào)整大小之后的圖片:

System.Drawing. Image i = resizeImage(b, new Size(100, 100));

 輸出結(jié)果:

到此這篇關(guān)于C#中調(diào)整圖像大小的步驟詳解的文章就介紹到這了,更多相關(guān)C#圖像大小內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

齐齐哈尔市| 湖口县| 二连浩特市| 佛学| 延长县| 杭锦旗| 绩溪县| 奉贤区| 正阳县| 千阳县| 清镇市| 南京市| 齐河县| 咸宁市| 德安县| 乌鲁木齐县| 胶南市| 宝鸡市| 广元市| 谢通门县| 伊宁县| 察雅县| 皮山县| 永州市| 诸暨市| 唐海县| 亳州市| 普格县| 廉江市| 黑龙江省| 灵石县| 招远市| 肇东市| 大理市| 敦煌市| 宜阳县| 定州市| 康定县| 科尔| 泉州市| 额敏县|