กรอง DIB ผ่าน C#
สร้างแอป .NET ของคุณเองเพื่อกรองไฟล์ DIB โดยใช้ API ฝั่งเซิร์ฟเวอร์
วิธีการกรองไฟล์ DIB โดยใช้ C#
แม้แต่ภาพที่สมบูรณ์แบบที่สุดก็สามารถปรับปรุงเพิ่มเติมหรือแปลงเป็นผลงานศิลปะที่แตกต่างและมีเอกลักษณ์โดยสิ้นเชิงได้ ใช้ฟิลเตอร์เพื่อให้ได้เอฟเฟกต์ภาพที่หลากหลาย ตัวอย่างเช่น คุณสามารถทำให้ภาพคมชัดขึ้น หรือในทางกลับกัน เพิ่มความเบลอ ปรับให้เรียบ หรือกำจัดสัญญาณรบกวนสีได้ ฟิลเตอร์ยังมีประโยชน์อันล้ำค่าเมื่อคุณต้องการสร้างความเป็นเอกลักษณ์ให้กับภาพของคุณ เพื่อให้บรรลุเป้าหมายนี้ ให้ใช้เอฟเฟกต์ที่ต้องการหรือรวมเอฟเฟกต์ต่างๆ วิธีการนี้ช่วยให้คุณสามารถปรับแต่งการไล่ระดับสี กำจัดสัญญาณรบกวน และเพิ่มความคมชัดของขอบของวัตถุในภาพถ่ายไปพร้อมๆ กัน เพื่อกรองไฟล์ DIB เราจะใช้ Aspose.Imaging for .NET API ซึ่งเป็น API การจัดการและการแปลงรูปภาพที่มีคุณลักษณะหลากหลาย มีประสิทธิภาพ และใช้งานง่ายสำหรับแพลตฟอร์ม C# เปิด NuGet ตัวจัดการแพ็คเกจ ค้นหา ** Aspose.Imaging ** และติดตั้ง คุณสามารถใช้คำสั่งต่อไปนี้จาก Package Manager Console
Package Manager Console Command
PM> Install-Package Aspose.Imaging
ขั้นตอนในการกรอง DIBs ผ่าน C#
คุณต้องใช้ aspose.imaging.dll เพื่อลองใช้เวิร์กโฟลว์ต่อไปนี้ในสภาพแวดล้อมของคุณเอง
- โหลดไฟล์ DIB ด้วยวิธี Image.Load
- กรองภาพ;
- บันทึกภาพที่บีบอัดลงในแผ่นดิสก์ในรูปแบบที่รองรับโดย Aspose.Imaging
ความต้องการของระบบ
Aspose.Imaging สำหรับ .NET ได้รับการสนับสนุนในระบบปฏิบัติการหลักทั้งหมด เพียงตรวจสอบให้แน่ใจว่าคุณมีข้อกำหนดเบื้องต้นดังต่อไปนี้
- Microsoft Windows หรือระบบปฏิบัติการที่เข้ากันได้กับ .NET Framework, .NET Core, Windows Application, ASP.NET Web Application
- สภาพแวดล้อมการพัฒนาเช่น Microsoft Visual Studio
- Aspose.Imaging สำหรับ .NET ที่อ้างอิงในโครงการของคุณ
กรองภาพ DIB - .NET
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Bmp; | |
using Aspose.Imaging.FileFormats.Dicom; | |
using Aspose.Imaging.FileFormats.Emf; | |
using Aspose.Imaging.FileFormats.Jpeg; | |
using Aspose.Imaging.FileFormats.Jpeg2000; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.FileFormats.Psd; | |
using Aspose.Imaging.FileFormats.Tiff.Enums; | |
using Aspose.Imaging.ImageFilters.FilterOptions; | |
using Aspose.Imaging.ImageOptions; | |
using Aspose.Imaging.Masking; | |
using Aspose.Imaging.Masking.Options; | |
using Aspose.Imaging.Masking.Result; | |
using Aspose.Imaging.Sources; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
string templatesFolder = @"c:\Users\USER\Downloads"; | |
MedianFilter(); | |
void SmallRectangularFilter() | |
{ | |
FilterImages(image => | |
{ | |
//https://apireference.aspose.com/imaging/net/aspose.imaging.imagefilters.filteroptions/smallrectangularfilteroptions | |
var filterRect = new Aspose.Imaging.Rectangle(image.Width / 6, image.Height / 6, image.Width * 2 / 3, image.Height * 2 / 3); | |
image.Filter(filterRect, new SmallRectangularFilterOptions()); | |
}, "smallrectangular"); | |
} | |
void BigRectangularFilter() | |
{ | |
FilterImages(image => | |
{ | |
//https://apireference.aspose.com/imaging/net/aspose.imaging.imagefilters.filteroptions/bigrectangularfilteroptions | |
var filterRect = new Aspose.Imaging.Rectangle(image.Width / 6, image.Height / 6, image.Width * 2 / 3, image.Height * 2 / 3); | |
image.Filter(filterRect, new BigRectangularFilterOptions()); | |
}, "bigrectangular"); | |
} | |
void SharpenFilter() | |
{ | |
FilterImages(image => | |
{ | |
//https://apireference.aspose.com/imaging/net/aspose.imaging.imagefilters.filteroptions/sharpenfilteroptions | |
var filterRect = new Aspose.Imaging.Rectangle(image.Width / 6, image.Height / 6, image.Width * 2 / 3, image.Height * 2 / 3); | |
image.Filter(filterRect, new SharpenFilterOptions()); | |
}, "sharpen"); | |
} | |
void MotionWienerFilter() | |
{ | |
FilterImages(image => | |
{ | |
//https://apireference.aspose.com/imaging/net/aspose.imaging.imagefilters.filteroptions/motionwienerfilteroptions | |
var filterRect = new Aspose.Imaging.Rectangle(image.Width / 6, image.Height / 6, image.Width * 2 / 3, image.Height * 2 / 3); | |
image.Filter(filterRect, new MotionWienerFilterOptions(20, 2, 0)); | |
}, "motionwiener"); | |
} | |
void BilateralSmoothingFilter() | |
{ | |
FilterImages(image => | |
{ | |
//https://apireference.aspose.com/imaging/net/aspose.imaging.imagefilters.filteroptions/bilateralsmoothingfilteroptions | |
var filterRect = new Aspose.Imaging.Rectangle(image.Width / 6, image.Height / 6, image.Width * 2 / 3, image.Height * 2 / 3); | |
image.Filter(filterRect, new BilateralSmoothingFilterOptions()); | |
}, "bilateralsmoothing"); | |
} | |
void GaussBlurFilter() | |
{ | |
FilterImages(image => | |
{ | |
//https://apireference.aspose.com/imaging/net/aspose.imaging.imagefilters.filteroptions/gaussianblurfilteroptions | |
var filterRect = new Aspose.Imaging.Rectangle(image.Width / 6, image.Height / 6, image.Width * 2 / 3, image.Height * 2 / 3); | |
image.Filter(filterRect, new GaussianBlurFilterOptions(5, 4)); | |
}, "gaussblur"); | |
} | |
void GaussWienerFilter() | |
{ | |
FilterImages(image => | |
{ | |
//https://apireference.aspose.com/imaging/net/aspose.imaging.imagefilters.filteroptions/gausswienerfilteroptions | |
var filterRect = new Aspose.Imaging.Rectangle(image.Width / 6, image.Height / 6, image.Width * 2 / 3, image.Height * 2 / 3); | |
image.Filter(filterRect, new GaussWienerFilterOptions(5, 5)); | |
}, "gausswiener"); | |
} | |
void MedianFilter() | |
{ | |
FilterImages(image => | |
{ | |
//https://apireference.aspose.com/imaging/net/aspose.imaging.imagefilters.filteroptions/medianfilteroptions | |
var filterRect = new Aspose.Imaging.Rectangle(image.Width / 6, image.Height / 6, image.Width * 2 / 3, image.Height * 2 / 3); | |
image.Filter(filterRect, new MedianFilterOptions(20)); | |
}, "median"); | |
} | |
void FilterImages(Action<RasterImage> doFilter, string filterName) | |
{ | |
List<string> rasterFormats = new List<string>() { "jpg", "png", "bmp", "apng", "dicom", | |
"jp2", "j2k", "tga", "webp", "tif", "gif","ico" }; | |
List<string> vectorFormats = new List<string>() { "svg", "otg", "odg", "eps", "wmf", "emf", "wmz", "emz", "cmx", "cdr" }; | |
List<string> allFormats = new List<string>(rasterFormats); | |
allFormats.AddRange(vectorFormats); | |
allFormats.ForEach( | |
formatExt => | |
{ | |
var inputFile = Path.Combine(templatesFolder, $"template.{formatExt}"); | |
bool isVectorFormat = vectorFormats.IndexOf(formatExt) > -1; | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = RasterizeVectorImage(formatExt, inputFile); | |
} | |
var outputFile = Path.Combine(templatesFolder, $"{filterName}_{formatExt}.png"); | |
Console.WriteLine($"Processing {formatExt}"); | |
using (var image = (RasterImage)Image.Load(inputFile)) | |
{ | |
doFilter(image); | |
//If image is multipage save each page to png to demonstrate results | |
if (image is IMultipageImage multiPage && multiPage.PageCount > 1) | |
{ | |
for (var pageIndex = 0; pageIndex < multiPage.PageCount; pageIndex++) | |
{ | |
string fileName = $"{filterName}_page{pageIndex}_{formatExt}.png"; | |
multiPage.Pages[pageIndex].Save(templatesFolder + fileName, new PngOptions()); | |
File.Delete(templatesFolder + fileName); | |
} | |
} | |
else | |
{ | |
image.Save(outputFile, new PngOptions()); | |
File.Delete(outputFile); | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
File.Delete(inputFile); | |
} | |
} | |
); | |
} | |
string RasterizeVectorImage(string formatExt, string inputFile) | |
{ | |
string outputFile = Path.Combine(templatesFolder, $"rasterized.{formatExt}.png"); | |
using (var image = Image.Load(inputFile)) | |
{ | |
image.Save(outputFile, new PngOptions()); | |
} | |
return outputFile; | |
} |
เกี่ยวกับ Aspose.Imaging สำหรับ .NET API
Aspose.Imaging API เป็นโซลูชันการประมวลผลรูปภาพเพื่อสร้าง แก้ไข วาดหรือแปลงรูปภาพ (ภาพถ่าย) ภายในแอปพลิเคชัน นำเสนอ: การประมวลผลภาพข้ามแพลตฟอร์ม รวมถึงแต่ไม่จำกัดเพียงการแปลงระหว่างรูปแบบภาพต่างๆ (รวมถึงการประมวลผลภาพแบบหลายหน้าหรือหลายเฟรมแบบเดียวกัน) การปรับเปลี่ยน เช่น การวาด การทำงานกับภาพกราฟิกดั้งเดิม การแปลงภาพ (ปรับขนาด ครอบตัด พลิกและหมุน , ไบนารี, ระดับสีเทา, ปรับ), คุณสมบัติการจัดการภาพขั้นสูง (การกรอง, การแยกสี, การปิดบัง, การเดสก์) และกลยุทธ์การปรับหน่วยความจำให้เหมาะสม เป็นไลบรารีแบบสแตนด์อโลนและไม่ขึ้นกับซอฟต์แวร์ใด ๆ สำหรับการทำงานของรูปภาพ คุณสามารถเพิ่มคุณสมบัติการแปลงรูปภาพประสิทธิภาพสูงด้วย API ดั้งเดิมภายในโปรเจ็กต์ได้อย่างง่ายดาย สิ่งเหล่านี้เป็น API ภายในองค์กรที่เป็นส่วนตัว 100% และอิมเมจได้รับการประมวลผลที่เซิร์ฟเวอร์ของคุณกรอง DIB ผ่านแอปออนไลน์
กรองเอกสาร DIB โดยไปที่ เว็บไซต์ Live Demos การสาธิตสดมีประโยชน์ดังต่อไปนี้
DIB คืออะไร DIB รูปแบบไฟล์
ไฟล์ DIB (Device Independent Bitmap) เป็นไฟล์ภาพแรสเตอร์ที่มีโครงสร้างคล้ายกับไฟล์ Bitmap มาตรฐาน (BMP) แต่มีส่วนหัวต่างกัน สามารถเปิดได้ด้วยแอพพลิเคชั่นเกือบทั้งหมดที่สามารถเปิดไฟล์ BMP มาตรฐานบน Windows เช่นเดียวกับ macOS DIB เป็นไฟล์ไบนารีและมีรูปแบบไฟล์ที่ซับซ้อนคล้ายกับ BMP
อ่านเพิ่มเติมรูปแบบตัวกรองอื่นๆ ที่รองรับ
เมื่อใช้ C# เราสามารถกรองรูปแบบต่างๆ ได้อย่างง่ายดายรวมถึง