IronBarcode 操作指南 圖像校正 使用 C# 影像校正篩選器來改善 BarCode 解碼。 Hairil Hasyimi Bin Omar 更新:2026年1月10日 下載 IronBarcode NuGet 下載 DLL 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronBarcode提供內建的影像修正篩選器,如SharpenFilter和ContrastFilter,可程式化地強化模糊或不完美的 BarCode 影像,提高讀取精準度,而不需要外部影像編輯軟體或重新擷取影像。 不是每張圖像都是完美的,圖像品質差是妨礙 IronBarcode 成功讀取條碼的主要因素之一。 與其重新擷取影像或使用外部影像增強軟體,IronBarcode 提供內建濾鏡,可程式化地改善影像品質。 這些過濾器有助於 IronBarcode 讀取困難的圖像,並提高整體精確度。 繼續閱讀,了解 IronBarcode 中可用的影像校正濾鏡、它們對影像的影響以及如何應用它們。 如需更全面的條碼讀取技巧,請查看我們的 讀取 BarCode 教程。 快速入門:應用銳利化和對比濾鏡來改善條碼讀取 只需一個步驟,即可使用 BarcodeReaderOptions 中的 ImageFilterCollection 應用 IronBarcode 的 SharpenFilter 和 ContrastFilter 。 這可改善 BarCode 掃描功能,且只需最少的設定,對外部工具的需求為零。 立即開始使用 NuGet 建立 PDF 檔案: 使用 NuGet 套件管理器安裝 IronBarcode PM > Install-Package BarCode 複製並運行這段程式碼。 BarcodeResults results = IronBarCode.BarcodeReader.Read("input.png", new IronBarCode.BarcodeReaderOptions { ImageFilters = new IronBarCode.ImageFilterCollection() { new IronBarCode.SharpenFilter(3.5f), new IronBarCode.ContrastFilter(2.0f) } }); 部署到您的生產環境進行測試 立即開始在您的專案中使用 IronBarcode,免費試用! 免費試用30天 ### 最小工作流程(5 個步驟) 下載 C# 庫以使用影像校正濾鏡 探索所有可用的圖像校正濾鏡 使用自訂值設定每個篩選器 對不完美的影像樣本套用濾鏡 從增強影像中擷取 BarCode 值 如何套用影像篩選器來改善條碼讀取? 若要套用篩選器,請實體化 ImageFilterCollection 類別,並個別建立每個篩選器的實體。 然後將該物件指派給BarcodeReaderOptions物件的ImageFilters屬性。 將選項物件和範例圖像一起傳遞給Read方法。 如需進階安裝選項,請造訪我們的 NuGet 套件指南。 使用以下圖片作為我們的範例圖片。 範例影像 圖片看起來相當模糊。 不過,亮度尚可接受,白色和黑色也能區分。 因此,至少應用 SharpenFilter 和 ContrastFilter 來改善 BarCode 的可讀性。 請參考以下的程式碼片段,將濾鏡套用至影像、讀取影像,並將結果顯示在控制台。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-apply-filter.cs using IronBarCode; using System; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection() { new SharpenFilter(3.5f), new ContrastFilter(2) }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Write the result value to console foreach (BarcodeResult result in results) { Console.WriteLine(result.Text); } Imports IronBarCode Imports System Private options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection() From { New SharpenFilter(3.5F), New ContrastFilter(2) } } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Write the result value to console For Each result As BarcodeResult In results Console.WriteLine(result.Text) Next result $vbLabelText $csharpLabel 上面的程式碼片段會套用篩選器、讀取條碼,並將篩選過的影像匯出到磁碟。 樣本與篩選圖片的比較如下所示。 範例影像 過濾後的樣品 IronBarcode 提供哪些圖像校正濾鏡? IronBarcode 提供多種影像濾鏡,專門用於影像修正。 這些篩選器可協助讀取不完美的 BarCode 影像,並提高讀取精確度。 然而,了解這些篩選器的運作方式,才能選擇合適的篩選器,並避免因使用太多篩選器或使用錯誤的篩選器而造成效能問題。 可用的篩選條件包括 自適應閾值過濾器 二進位閾值過濾器 BrightnessFilter- ContrastFilter 對比過濾器 反向篩選器 SharpenFilter- ErodeFilter- DilateFilter- HistogramEqualizationFilter- 模糊濾鏡 高斯模糊濾波器 BilateralFilter- MedianBlurFilter應用篩選器的順序是基於它們在 ImageFilterCollection 中的位置。 如需這些篩選器的詳細 API 文件,請造訪我們的 API Reference。 自適應閾值篩選器如何運作? AdaptiveThresholdFilter 是 IronBarcode 中可用的篩選器,可將 Bradley Adaptive Threshold 技術套用至影像,自動決定影像二值化的閾值。 此濾鏡非常適合用於光照不均勻、背景強度變化較大的影像。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-adaptive-threshold.cs using IronBarCode; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new AdaptiveThresholdFilter(0.9f), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("adaptiveThreshold_0.9.png"); Imports IronBarCode Private options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New AdaptiveThresholdFilter(0.9F)} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("adaptiveThreshold_0.9.png") $vbLabelText $csharpLabel 以下是使用不同值套用篩選器後的輸出結果。 預設值 0.9 值 建構器會接受額外的設定參數: Upper:閾值的上色 (白色)。 Lower:閾值的下層 (黑色) 顏色。 閾值:二值化的閾值限制 (0.0-1.0)。 Rectangle:要套用處理器的矩形區域。 如上面的輸出影像所示,影像經過二值化處理,只有 黑 和 白 兩種顏色。 雖然對於 BarCode 讀取來說似乎仍不理想,但濾鏡需要組合使用。 請嘗試使用參數靈敏度以達到最佳效果。 二進位閾值篩選器如何運作? BinaryThresholdFilter 透過在指定的臨界值分割像素,比較色彩元件的亮度,來過濾影像。 與 AdaptiveThresholdFilter 相似,如果使用不當,此過濾器可能會引入新的或不想要的雜訊。 然而,IronBarcode 已為篩選器屬性設定預設值。 與 AdaptiveThresholdFilter 相似,BinaryThresholdFilter 也接受相同的附加參數進行設定: Upper:閾值的上色 (白色)。 Lower:閾值的下層 (黑色) 顏色。 閾值:二值化的閾值限制 (0.0-1.0)。 Rectangle:要套用處理器的矩形區域。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-binary-threshold.cs using IronBarCode; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new BinaryThresholdFilter(0.9f) }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("binaryThreshold_0.9.png"); Imports IronBarCode Private options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New BinaryThresholdFilter(0.9F)} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("binaryThreshold_0.9.png") $vbLabelText $csharpLabel 以下是對範例影像套用濾鏡後的範例輸出結果。 預設值 0.9 值 觀察上面的輸出影像,樣本已二值化為黑白顏色。 然而,由於條碼條被消除,並引進新的雜訊,此濾鏡顯然不適合此影像。 如需處理困難的 BarCode 情境,請參閱我們的 無法辨識條碼的疑難排解指南。 如何調整影像亮度以獲得更好的條碼讀取效果? BrightnessFilter是 IronBarcode 影像濾鏡集合中的另一個重要濾鏡。 顧名思義,此濾鏡可調整條碼影像的亮度。 此構成器的輸入會改變輸出影像中的 Amount 亮度。 預設值為 1,這表示影像保持不變。 值為 0 會產生完全黑色的影像,而值高於 1 則會使影像更亮。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-brightness.cs using IronBarCode; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new BrightnessFilter(1.5f), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("brightness_1.5.png"); Imports IronBarCode Private options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New BrightnessFilter(1.5F)} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("brightness_1.5.png") $vbLabelText $csharpLabel 下面這張圖是將此濾鏡套用到範例輸入後的輸出影像。 預設值 1.5 值 如何使用對比度篩選器來增強 BarCode 影像? ContrastFilter 可調整影像的對比度。 影像對比度是指影像中不同元素之間顏色強度的差異。 提高對比度可以增強細節的可見性,使影像看起來生動鮮明;而降低對比度則會使影像看起來柔和低調。 有關條碼自訂的詳細資訊,請參閱我們的 自訂條碼樣式指南。 預設值為 1,這表示影像保持不變。 值為 0 會產生完全灰色的影像,而值高於 1 則會增加影像的對比度。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-contrast.cs using IronBarCode; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new ContrastFilter(1.5f), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("contrast_1.5.png"); Imports IronBarCode Private options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New ContrastFilter(1.5F)} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("contrast_1.5.png") $vbLabelText $csharpLabel 將此濾鏡套用至範例輸入,即可產生下圖。 預設值 1.5 值 何時應該使用反向篩選器? 此濾鏡可將影像內部的顏色反轉,變成相反的顏色,例如白色變成黑色,黑色變成白色。在讀取有背景顏色的 BarCode 影像時特別有用。 與 BinaryThresholdFilter 不同,此濾鏡可直接反轉顏色,而無需指定敏感度。 此外,此濾鏡可與 CropRectangle 搭配使用,以指定影像中需要反轉顏色的位置,而不是反轉整個影像的顏色。 在我們的作物區域教程中瞭解有關指定作物區域的更多資訊。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-invert.cs using IronBarCode; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new InvertFilter(), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("invert.png"); Imports IronBarCode Private options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New InvertFilter()} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("invert.png") $vbLabelText $csharpLabel 下面的輸出影像是將此濾鏡套用至範例輸入影像的結果。 原圖 倒 如何使用銳化篩選器修復模糊的 BarCode 影像? IronBarcode 提供銳化篩選器。 此濾鏡可以增強影像的清晰度,在處理模糊影像時非常有用。 在實體化濾鏡物件時,透過調整 Sigma 值來操控此濾鏡,以調整影像的銳利度。 預設值為 3。增加 sigma 值可以提高影像清晰度。 如需其他效能最佳化選項,請參閱我們的 讀取速度選項指南。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-sharpen.cs using IronBarCode; using System; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new SharpenFilter(0.5f), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("sharpen_0.5.png"); Imports IronBarCode Imports System Private options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New SharpenFilter(0.5F)} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("sharpen_0.5.png") $vbLabelText $csharpLabel The image below is the sharpened version of the sample input image. 預設值 0.5 值 將上面的圖片與原始圖片比較,它顯得更清晰,並有助於使用 IronBarcode 讀取條碼。 大多數情況下, SharpenFilter總是與ImageFilterCollection類別中的其他濾鏡一起應用。 Erode 過濾器有何用途? ErodeFilter 可移除微小的白噪音,並透過移除形狀邊緣附近的像素來加粗 BarCode 條碼。此濾鏡最適合用於條碼背景有大量白色斑點的情況,或是條碼影像解析度太低或模糊,導致條碼合併的情況。 ErodeFilter可使條形圖變得更粗,同時移除背景中的白色斑點。 如需處理不完美圖像的更多資訊,請參閱我們的 不完美 BarCode 示例。 輸入代表篩選器 kernelSize 的整數,以增加侵蝕的效果。 卷積核尺寸越大,對輸入影像的影響就越強。 請注意,kernelSize 是一個正方形,在這個範例中是一個 5x5 核心。 以 ErodeFilter 為例,使用較大的核心大小來展示濾波器的效果。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-erode.cs using IronBarCode; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new ErodeFilter(5), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("erodeFilter.jpg"); Imports IronBarCode Dim options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From { New ErodeFilter(5) } } ' Apply options and read the barcode Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("erodeFilter.jpg") $vbLabelText $csharpLabel 原圖 侵蝕過濾器應用 比較上面的輸入和輸出影像,由於輸入較大的核心尺寸進行篩選時較為激進,因此有些條形會明顯變厚。 然而,整體畫面中的白色斑點減少了。 根據侵蝕濾鏡的性質,內核尺寸越大,如果過於激烈地應用,可能會擦除細條,如上圖所示。 透過變更 ErodeFilter 輸入的核心大小值,測試並改善效果。 Dilate 過濾器如何幫助條碼讀取? DilateFilter 的功能與ErodeFilter相反,它透過在物件邊界添加像素來擴展明亮區域(通常是背景)。 雖然此濾鏡可藉由填補細小縫隙或增強低對比度區域來修復損壞或模糊的 BarCode,但請注意其對 BarCode 條碼的效果與直覺不同。 由於擴張會放大明亮的空間,因此會間接變薄暗色元素,例如黑色 BarCode 條碼(假設背景為白色)。 這使得該過濾器在條碼條看起來過粗或合併的情況下特別有效,但過度使用可能會因條碼條過窄而降低掃描精度。 與上述類似,透過輸入代表篩選器的 kernelSize 的整數來增加篩選器的效果。 在下面的範例中,請使用較大的核心大小來展示 DilateFilter的效果。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-dilate.cs using IronBarCode; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new DilateFilter(5), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("dilateFilter.jpg"); Imports IronBarCode Dim options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From { New DilateFilter(5) } } ' Apply options and read the barcode Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("dilateFilter.jpg") $vbLabelText $csharpLabel 原圖 應用擴張濾波器 如上圖所示,積極使用 DilateFilter 有可能會破壞條碼結構,合併間距較近的條碼,並在條碼中產生靜音區。 根據輸入的影像,將核心大小值變得更大或更小,以測試並改善對影像的影響。 何時應該使用 HistogramEqualization 篩選器? HistogramEqualizationFilter 可透過重新分配像素強度來增強影像對比,以改善清晰度。 它最常用於條碼對比度較低的情況,例如褪色或褪色的影像,或是光線不均勻的影像,例如暗影或強光。 透過分析影像直方圖(像素亮度分佈),它透過拉伸強度範圍來增強對比度,從而重新分配像素值,使暗像素變得更暗,亮像素變得更亮。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-histogram-equalization-filter.cs using IronBarCode; BarcodeReaderOptions options = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new HistogramEqualizationFilter(), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.png", options); // Export file to disk results.ExportFilterImagesToDisk("histogramEqualizationFilter.jpg"); Imports IronBarCode Dim options As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From { New HistogramEqualizationFilter() } } ' Apply options and read the barcode Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options) ' Export file to disk results.ExportFilterImagesToDisk("histogramEqualizationFilter.jpg") $vbLabelText $csharpLabel 原圖 已應用直方圖均衡化濾波器 如上圖所示,與原始圖片相比,黑條明顯變暗,空格明顯變亮。 哪些模糊過濾器可以幫助降低 BarCode 的雜訊? GaussianBlur 過濾器如何降低影像雜訊? GaussianBlurFilter 會將高斯模糊套用至影像。 此濾鏡通常可降低影像中的雜訊。 如需處理不完美 BarCode 的全面指南,請參閱我們的 影像方向修正教學。 此濾波器的工作原理是使用高斯函數對影像中相鄰像素值進行平均。 此方法依賴兩個可調因素: -核:用於對像素進行平均的矩陣。 Sigma:控制模糊強度的數值。 預設的 核心大小為 3x3 像素,預設的 Sigma 值為 3.0 ,會產生適度的模糊。 增加 Sigma 值會產生更強的模糊效果。 您也可以自訂 核心,以控制模糊濾鏡平均的鄰域大小。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-gaussianblur.cs using IronBarCode; BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new GaussianBlurFilter(3, 3, 3.0f), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sharpen.webp", myOptionsExample); // Export file to disk results.ExportFilterImagesToDisk("gaussianBlur.png"); Imports IronBarCode Private myOptionsExample As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New GaussianBlurFilter(3, 3, 3.0F)} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sharpen.webp", myOptionsExample) ' Export file to disk results.ExportFilterImagesToDisk("gaussianBlur.png") $vbLabelText $csharpLabel 將此濾鏡套用至範例輸入,即可產生下圖。 銳化影像 高斯模糊影像 何時應該使用雙邊篩選器? BilateralFilter 可在保留邊緣的同時平滑影像。 不同於簡單的模糊技術會均勻地影響所有像素,Bilateral Filter 會同時考慮顏色差異和像素距離,使其能有效地進行邊緣保留平滑處理。 此方法依賴三個可調因素: NeighborhoodDiameter:像素鄰域直徑 (預設值:5)。 SigmaColor:決定色差影響的顏色影響(預設:75.0)。 SigmaSpace:決定距離影響的空間影響(預設:75.0)。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-bilateral.cs using IronBarCode; BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new BilateralFilter(5, 75, 75), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sharpen.webp", myOptionsExample); // Export file to disk results.ExportFilterImagesToDisk("bilateral.png"); Imports IronBarCode Private myOptionsExample As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New BilateralFilter(5, 75, 75)} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sharpen.webp", myOptionsExample) ' Export file to disk results.ExportFilterImagesToDisk("bilateral.png") $vbLabelText $csharpLabel 將此濾鏡套用至範例輸入,即可產生下圖。 銳化影像 雙側影像 是什麼讓 MedianBlur 濾波器在降低雜訊方面與眾不同? MedianBlurFilter會以周圍像素的中值取代每個像素的值,以減少影像中的雜訊。 此濾鏡尤其擅長保留邊緣,同時去除雜訊。若要探索更多關於條碼讀取設定的資訊,請造訪我們的 條碼讀取器設定指南。 KernelSize:用於計算中位數的鄰區大小(必須是奇數,預設值:5)。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-medianblur.cs using IronBarCode; BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new MedianBlurFilter(5), }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sharpen.webp", myOptionsExample); // Export file to disk results.ExportFilterImagesToDisk("medianBlur.png"); Imports IronBarCode Private myOptionsExample As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From {New MedianBlurFilter(5)} } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sharpen.webp", myOptionsExample) ' Export file to disk results.ExportFilterImagesToDisk("medianBlur.png") $vbLabelText $csharpLabel 將此濾鏡套用至範例輸入,即可產生下圖。 銳化影像 中位數模糊影像 如何在每個處理步驟中儲存篩選過的影像? 在對 BarCode 應用多個篩選器時,檢視每個篩選方法之後的輸出可能會有困難。 此功能允許在套用每個濾鏡後,按處理順序儲存濾鏡後的影像。 若要啟用此功能,請先將true傳遞給ImageFilterCollection建構子。 然後使用 ExportFilterImagesToDisk 方法提供輸出影像的路徑和名稱。 如需儲存條碼的更多範例,請參閱我們的 將條碼轉換為影像範例。 :path=/static-assets/barcode/content-code-examples/how-to/image-correction-save-iterations.cs using IronBarCode; BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions() { // Choose which filters are to be applied (in order) ImageFilters = new ImageFilterCollection(true) { new SharpenFilter(3.5f), new AdaptiveThresholdFilter(0.5f), new ContrastFilter(2) }, }; // Apply options and read the barcode BarcodeResults results = BarcodeReader.Read("sample.webp", myOptionsExample); // Export file to disk results.ExportFilterImagesToDisk("filteredImage.png"); Imports IronBarCode Private myOptionsExample As New BarcodeReaderOptions() With { .ImageFilters = New ImageFilterCollection(True) From { New SharpenFilter(3.5F), New AdaptiveThresholdFilter(0.5F), New ContrastFilter(2) } } ' Apply options and read the barcode Private results As BarcodeResults = BarcodeReader.Read("sample.webp", myOptionsExample) ' Export file to disk results.ExportFilterImagesToDisk("filteredImage.png") $vbLabelText $csharpLabel 過濾器按照程式碼的順序應用,輸出圖像反映了每次迭代的結果: Sharpen -> Sharpen 之後 Sharpen + AdaptiveThreshold -> AdaptiveThreshold 之後 Sharpen + AdaptiveThreshold + Contrast -> Contrast 之後 範例影像 磨利後 自適應閾值後 對比後 除了 ImageFilters 屬性之外,為了更精確地閱讀,請在 BarcodeReaderOptions 中加入其他屬性; 更多資訊請參閱這篇文章。 常見問題解答 什麼是影像校正篩選器?為什麼條碼讀取需要這些篩選器? IronBarcode 中的圖像校正過濾器是內置的工具,可程式化地增強模糊或不完美的條碼圖像。它們是必不可少的,因為低劣的圖像質量是妨礙成功讀取條碼的主要因素之一。IronBarcode 提供的濾鏡,如 SharpenFilter 和 ContrastFilter,可以提高讀取準確性,而不需要外部圖像編輯軟件或重新擷取圖像。 如何應用影像修正濾鏡來改善 BarCode 掃描? 要在 IronBarcode 中應用篩選器,請建立一個 ImageFilterCollection 實例,並將個別篩選器實例加入其中。然后将此集合分配给 BarcodeReaderOptions 的 ImageFilters 属性,并将其传递给 Read 方法。例如:new BarcodeReaderOptions { ImageFilters = new ImageFilterCollection() { new SharpenFilter(3.5f), new ContrastFilter(2.0f) }。}. 建議使用哪些影像過濾器來處理模糊的 BarCode 影像? 對於模糊的條碼影像,IronBarcode 建議至少使用 SharpenFilter 和 ContrastFilter。SharpenFilter 可增強模糊圖像的邊緣清晰度,而 ContrastFilter 可改善明暗區域之間的區別。這些濾鏡共同作用,使 BarCode 更易於閱讀,而無需進行外部影像處理。 我可以自訂影像修正濾鏡的強度嗎? 是的,IronBarcode 允許您使用自訂值配置每個篩選器。例如,SharpenFilter 接受浮點參數(如 3.5f)來控制銳化強度,而 ContrastFilter 則接受參數(如 2.0f)來調整對比層級。這種自訂功能有助於針對不同的影像條件,最佳化濾鏡的效果。 我需要外部影像編輯工具來增強 BarCode 影像嗎? 不,IronBarcode 透過提供內建的影像修正篩選器,免除了外部影像編輯工具的需求。這些程式化的濾鏡,如 SharpenFilter 和 ContrastFilter,可直接在您的 .NET 應用程式中提升影像品質,節省時間並避免依賴第三方軟體。 Hairil Hasyimi Bin Omar 立即與工程團隊聊天 軟體工程師 就像所有優秀的工程師一樣,Hairil 也是一位狂熱的學習者。他不斷精進 C#、Python 和 Java 的知識,利用這些知識為整個 Iron Software 的團隊成員增加價值。Hairil 從馬來西亞的 Universiti Teknologi MARA 大學加入 Iron Software 團隊,畢業於該校的化學與流程工程學系,並取得學士學位。 準備好開始了嗎? Nuget 下載 2,070,733 | 版本: 2026.2 剛剛發布 免費 NuGet 下載 總下載量:2,070,733 查看許可證