欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

C#怎么改變圖片大小并且重命名

這篇文章主要介紹“C#怎么改變圖片大小并且重命名”,在日常操作中,相信很多人在C#怎么改變圖片大小并且重命名問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”C#怎么改變圖片大小并且重命名”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

創(chuàng)新互聯(lián)專注于芮城網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供芮城營銷型網(wǎng)站建設(shè),芮城網(wǎng)站制作、芮城網(wǎng)頁設(shè)計(jì)、芮城網(wǎng)站官網(wǎng)定制、成都小程序開發(fā)服務(wù),打造芮城網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供芮城網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

添加NuGet包

選擇最新版就好了

安裝完成后右鍵項(xiàng)目重新生成方案

使用OpenCvSharp.CPlusPlus命名空間

using OpenCvSharp.CPlusPlus;

寫一個(gè)函數(shù)用來改變圖片大小并且重新命名

read_path是存儲(chǔ)圖片的文件夾的路徑,write_path是改變后圖片存儲(chǔ)的文件夾路徑,filename是圖片重命名,width和height分別為圖片修改后的寬和高

public static void ResizeImg(String read_path,String write_path,String filename,double width,double height) {      Mat img1 = new Mat(read_path);      Mat img2 = img1;      OpenCvSharp.CPlusPlus.Size size = new OpenCvSharp.CPlusPlus.Size(width, height);      Cv2.Resize(img1, img2, size, 0, 0);      Cv2.ImWrite(write_path+"\\"+ filename, img2);    }

在Main函數(shù)中使用該函數(shù)

static void Main(string[] args)    {      string dir_path = @"G:\TestImg";//讀取路徑      String write_path = "G:\\TestImg2";//存儲(chǔ)路徑      String[] filenames=Directory.GetFiles(dir_path);      for (int i = 0; i < filenames.Length; i++) {        ResizeImg(filenames[i], write_path, i + ".png", 200, 300);      }      Console.ReadKey();    }

運(yùn)行結(jié)果

完整代碼

using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using OpenCvSharp;using OpenCvSharp.CPlusPlus;using System.Runtime.InteropServices;using System.IO;namespace ResizeTest{  class Program  {    static void Main(string[] args)    {      string dir_path = @"G:\TestImg";//讀取路徑      String write_path = "G:\\TestImg2";//存儲(chǔ)路徑      String[] filenames=Directory.GetFiles(dir_path);      for (int i = 0; i < filenames.Length; i++) {        ResizeImg(filenames[i], write_path, i + ".png", 200, 300);      }      Console.ReadKey();    }    public static void ResizeImg(String read_path,String write_path,String filename,double width,double height) {      Mat img1 = new Mat(read_path);      Mat img2 = img1;      OpenCvSharp.CPlusPlus.Size size = new OpenCvSharp.CPlusPlus.Size(width, height);      Cv2.Resize(img1, img2, size, 0, 0);      Cv2.ImWrite(write_path+"\\"+ filename, img2);    }  }  }

到此,關(guān)于“C#怎么改變圖片大小并且重命名”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

名稱欄目:C#怎么改變圖片大小并且重命名
本文網(wǎng)址:http://chinadenli.net/article8/gigpip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作網(wǎng)站改版、移動(dòng)網(wǎng)站建設(shè)、全網(wǎng)營銷推廣、靜態(tài)網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)