Filtruj DIB przez C#
Twórz własne aplikacje .NET, aby filtrować pliki DIB przy użyciu interfejsów API po stronie serwera.
Jak filtrować pliki DIB za pomocą C#
Nawet najdoskonalszy obraz można jeszcze bardziej ulepszyć lub przekształcić w zupełnie inne i niepowtarzalne dzieło sztuki. Zastosuj filtry, aby uzyskać szeroką gamę efektów graficznych. Można na przykład wyostrzyć obraz lub odwrotnie, dodać rozmycie, wygładzić go lub wyeliminować szum kolorów. Filtry są również nieocenione, gdy chcesz nadać swojemu obrazowi wyjątkowości. Aby to osiągnąć, zastosuj pożądany efekt lub połącz różne efekty. Takie podejście pozwala udoskonalić przejścia kolorów, wyeliminować szumy, a jednocześnie poprawić ostrość krawędzi obiektów na zdjęciu. Aby filtrować pliki w formacie DIB, użyjemy Aspose.Imaging dla .NET API, który jest bogatym w funkcje, wydajnym i łatwym w użyciu interfejsem API do obróbki i konwersji obrazów dla platformy C#. Otwarty NuGet menedżer pakietów, szukaj Aspose.Obrazowanie i zainstaluj. Możesz również użyć następującego polecenia z konsoli Menedżera pakietów.
Polecenie konsoli menedżera pakietów
PM> Install-Package Aspose.Imaging
Kroki do filtrowania DIB przez C#
Potrzebujesz aspose.imaging.dll aby wypróbować następujący przepływ pracy we własnym środowisku.
- Załaduj pliki DIB za pomocą metody Image.Load
- Filtruj obrazy;
- Zapisz skompresowany obraz na dysku w formacie obsługiwanym przez Aspose.Imaging
wymagania systemowe
Aspose.Imaging dla .NET jest obsługiwane we wszystkich głównych systemach operacyjnych. Tylko upewnij się, że masz następujące wymagania wstępne.
- Microsoft Windows lub kompatybilny system operacyjny z .NET Framework, .NET Core, Windows Application, ASP.NET Web Application.
- Środowisko programistyczne, takie jak Microsoft Visual Studio.
- Aspose.Imaging dla platformy .NET, do której odwołuje się Twój projekt.
Filtruj obrazy w formacie 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; | |
} |
Informacje o Aspose.Imaging dla .NET API
Aspose.Imaging API to rozwiązanie do przetwarzania obrazów do tworzenia, modyfikowania, rysowania lub konwertowania obrazów (zdjęć) w aplikacjach. Oferuje: wieloplatformowe przetwarzanie obrazu, w tym między innymi konwersje między różnymi formatami obrazu (w tym jednolite przetwarzanie obrazu wielostronicowego lub wieloklatkowego), modyfikacje takie jak rysowanie, praca z prymitywami graficznymi, przekształcenia (zmiana rozmiaru, przycinanie, odwracanie i obracanie , binaryzacja, skala szarości, dostosowanie), zaawansowane funkcje manipulacji obrazem (filtrowanie, dithering, maskowanie, prostowanie) oraz strategie optymalizacji pamięci. Jest to samodzielna biblioteka i nie zależy od żadnego oprogramowania do obsługi obrazów. W projektach można łatwo dodać wysokowydajne funkcje konwersji obrazów za pomocą natywnych interfejsów API. Są to w 100% prywatne lokalne interfejsy API, a obrazy są przetwarzane na Twoich serwerach.Filtruj DIB przez aplikację online
Filtruj dokumenty w formacie DIB, odwiedzając naszą witrynę demonstracyjną na żywo . Demo na żywo ma następujące zalety
DIB Co jest DIB Format pliku
Plik DIB (Device Independent Bitmap) to plik obrazu rastrowego, który ma podobną strukturę do standardowych plików bitmapowych (BMP), ale ma inny nagłówek. Można go otworzyć za pomocą prawie wszystkich aplikacji, które mogą otwierać standardowy plik BMP w systemie Windows i macOS. DIB to pliki binarne i mają złożony format pliku podobny do BMP.
Czytaj więcejInne obsługiwane formaty filtrów
Używając C#, można łatwo filtrować różne formaty, w tym.