本文介绍了调整亮度对比度的图像和γ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是一个简单的方法来调整亮度对比度.NET中的图像和γ
将发布自己的答案以后发现它。
解决方案
我已经找到了一个很好的和简单的例子here
位图originalImage;
位图adjustedImage;
浮动亮度= 1.0F; //亮度无变化
浮对比度= 2.0f; //两次对比
浮伽马= 1.0F; //伽玛无变化
浮adjustedBrightness =亮度 - 1.0F;
//创建矩阵,将照亮和对比图像
浮动[] [] ptsArray = {
新的浮动[] {相反,0,0,0,0},//规模红
新的浮动[] {0,相反,0,0,0},//规模的绿色
新的浮动[] {0,0,相反,0,0},//规模蓝色
新浮法[] {0,0,0,1.0F,0},//不具有可扩展阿尔法
新浮法[] {adjustedBrightness,adjustedBrightness,adjustedBrightness,0,1}};
imageAttributes =新ImageAttributes();
imageAttributes.ClearColorMatrix();
imageAttributes.SetColorMatrix(新嘉洛斯(ptsArray),ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
imageAttributes.SetGamma(伽马,ColorAdjustType.Bitmap);
图形G = Graphics.FromImage(adjustedImage);
g.DrawImage(originalImage,新的Rectangle(0,0,adjustedImage.Width,adjustedImage.Height)
,0,0,originalImage.Width,originalImage.Height,
GraphicsUnit.Pixel,imageAttributes);
What is an easy way to adjust brightness contrast and gamma of an Image in .NET
Will post the answer myself to find it later.
解决方案
I've found a good and easy example here
Bitmap originalImage;
Bitmap adjustedImage;
float brightness = 1.0f; // no change in brightness
float contrast = 2.0f; // twice the contrast
float gamma = 1.0f; // no change in gamma
float adjustedBrightness = brightness - 1.0f;
// create matrix that will brighten and contrast the image
float[][] ptsArray ={
new float[] {contrast, 0, 0, 0, 0}, // scale red
new float[] {0, contrast, 0, 0, 0}, // scale green
new float[] {0, 0, contrast, 0, 0}, // scale blue
new float[] {0, 0, 0, 1.0f, 0}, // don't scale alpha
new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}};
imageAttributes = new ImageAttributes();
imageAttributes.ClearColorMatrix();
imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);
Graphics g = Graphics.FromImage(adjustedImage);
g.DrawImage(originalImage, new Rectangle(0,0,adjustedImage.Width,adjustedImage.Height)
,0,0,originalImage.Width,originalImage.Height,
GraphicsUnit.Pixel, imageAttributes);
这篇关于调整亮度对比度的图像和γ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!