Learn how to adjust contrast, brightness, and gamma of an image in C#: https://blog.aspose.com/2021/12/24/adjust-image-contrast-brightness-gamma-csharp/
Last active
December 24, 2021 13:31
-
-
Save aspose-com-gists/3a5e8e91b8f8a8f90f46a3557c434317 to your computer and use it in GitHub Desktop.
Adjust Contrast, Brightness, and Gamma of Images in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load an image in an instance of Image | |
using (Image image = Image.Load("image.png")) | |
{ | |
// Cast to raster image | |
RasterImage rasterImage = (RasterImage)image; | |
// Cache RasterImage for better performance | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Adjust the brightness | |
rasterImage.AdjustBrightness(70); | |
// Save image | |
image.Save("image-updated-bightness.png"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load an image in an instance of Image | |
using (Image image = Image.Load("image.png")) | |
{ | |
// Cast to raster image | |
RasterImage rasterImage = (RasterImage)image; | |
// Cache RasterImage for better performance | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Adjust contrast | |
rasterImage.AdjustContrast(30); | |
// Save image | |
image.Save("image-updated-contrast.png"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load an image in an instance of Image | |
using (Image image = Image.Load("image.png")) | |
{ | |
// Cast to raster image | |
RasterImage rasterImage = (RasterImage)image; | |
// Cache RasterImage for better performance | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Adjust gamma | |
rasterImage.AdjustGamma(2.2f, 2.2f, 2.2f); | |
// Save image | |
image.Save("image-updated-gamma.png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment