翻譯|使用教程|編輯:莫成敏|2019-08-28 15:19:37.030|閱讀 361 次
概述:本文主要介紹整個(gè)文件夾中的圖像尺寸都太大了時(shí),如何調(diào)整整個(gè)圖像文件夾的大小。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
LEADTOOLS (Lead Technology)由Moe Daher and Rich Little創(chuàng)建于1990年,其總部設(shè)在北卡羅來(lái)納州夏洛特。LEAD的建立是為了使Daher先生在數(shù)碼圖象與壓縮技術(shù)領(lǐng)域的發(fā)明面向市場(chǎng)。在過(guò)去超過(guò)18年的發(fā)展歷程中,LEAD以其在全世界主要國(guó)家中占有的市場(chǎng)領(lǐng)導(dǎo)地位,在數(shù)碼圖象開(kāi)發(fā)工具領(lǐng)域中已成為既定的全球領(lǐng)導(dǎo)者。LEADTOOLS開(kāi)發(fā)與發(fā)布的LEAD是屢獲殊榮的開(kāi)發(fā)工具包。
本文主要介紹整個(gè)文件夾中的圖像尺寸都太大了時(shí),如何調(diào)整整個(gè)圖像文件夾的大小。看看具體怎么操作吧,感興趣的朋友不妨自己動(dòng)手試一試~
今天早上我收到了一個(gè)包含100多張各種演示截圖的文件夾。我需要這些來(lái)更新我們的網(wǎng)站。不幸的是,它們中的大多數(shù)對(duì)于頁(yè)面而言都太大了,需要調(diào)整大小。我快速創(chuàng)建了一個(gè).NET Core控制臺(tái)應(yīng)用程序來(lái)為我修復(fù)圖像大小。我編寫代碼,快速調(diào)整圖像大小。代碼如下,大家請(qǐng)享用吧!
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using System;using System.IO;namespace BatchResize_NetCore{ internal class Program { private static void Main(string[] args) { if (!SetLicense()) return; // TODO: Change these as needed const string filter = @"*.png"; const string sourceFolder = @"D:?temp?readme screenshots?"; var directoryInfo = new DirectoryInfo(sourceFolder); foreach (var file in directoryInfo.GetFiles(filter)) { ShowMessage($"Processing {file.Name}"); ResizeImage(file.FullName); } ShowMessage("Processing complete."); } public static void ResizeImage(string sourcePath, string destinationPath = null) { const float max = 500f; // The max width or height if (destinationPath == null) destinationPath = sourcePath; LeadSize CalculateNewSize(RasterImage i) { var ratio = i.Width > i.Height ? max / i.Width : max / i.Height; return new LeadSize((int)(i.Width * ratio), (int)(i.Height * ratio)); } using (var codecs = new RasterCodecs()) using (var image = codecs.Load(sourcePath)) { // 9 is slower but results in small file size // //www.leadtools.com/help/leadtools/v20/dh/co/codecspngsaveoptions-qualityfactor.html codecs.Options.Png.Save.QualityFactor = 9; if (image.Width <= 500 && image.Height <= max) return; // does not need to be resized var newSize = CalculateNewSize(image); new SizeCommand { Width = newSize.Width, Height = newSize.Height, Flags = RasterSizeFlags.Bicubic | RasterSizeFlags.ScaleToGray }.Run(image); codecs.Save(image, destinationPath, RasterImageFormat.Png, image.BitsPerPixel); } } public static bool SetLicense() { try { // TODO: Replace these with the path to the LEADTOOLS license file const string licenseFilePath = null; var developerKey = null; if (developerKey != null) RasterSupport.SetLicense(licenseFilePath, developerKey); } catch (Exception ex) { Console.WriteLine(ex.Message); } return !RasterSupport.KernelExpired; } public static void ShowMessage(string message, bool error = false) { var origColor = Console.ForegroundColor; Console.ForegroundColor = error ? ConsoleColor.Red : ConsoleColor.Green; Console.WriteLine(message); Console.ForegroundColor = origColor; } }}
這些代碼快速解決文件夾中圖像的大小,節(jié)省那您的時(shí)間~
LEADTOOLS Document Imaging Developer Toolkit是多語(yǔ)言的文檔圖像處理控件,支持光符識(shí)別處理、條形碼掃描識(shí)別等。其主要功能包括綜合圖像注釋,專業(yè)的黑白圖像顯示(例如灰度級(jí)和偏黑),以及專業(yè)的黑白圖像處理。其它功能包括對(duì)黑白圖像的性能和內(nèi)存進(jìn)行優(yōu)化,文檔圖像清理(包括倒置文本,去邊框)以及使用LEADTOOLS Fast TWAIN和WIA進(jìn)行掃描。
想要購(gòu)買該產(chǎn)品正版授權(quán),或了解更多產(chǎn)品信息請(qǐng)點(diǎn)擊
掃描關(guān)注慧聚IT微信公眾號(hào),及時(shí)獲取最新動(dòng)態(tài)及最新資訊
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn