调整亮度对比度的图像和γ [英] Adjust brightness contrast and gamma of an image

查看:363
本文介绍了调整亮度对比度的图像和γ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一个简单的方法来调整亮度对比度.NET中的图像和γ

将发布自己的答案以后发现它。

解决方案

我已经找到了一个很好的和简单的例子<一href="http://blog.bee-eee.com/2008/01/23/c-adjusting-brightnesscontrast-and-gamma-of-an-image/">here

  

C#和GDI +有一种简单的方式来控制的绘制颜色。   这基本上是一个嘉洛斯。它是一个5×5矩阵,它被施加到   每种颜色,如果它被设置。调整亮度只是执行   翻译的颜色数据,和对比度上执行比例   颜色。伽玛是一个完全不同的形式变换,但它包含   在ImageAttributes它接受嘉洛斯。

 位图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

c# and gdi+ have a simple way to control the colors that are drawn. It’s basically a ColorMatrix. It’s a 5×5 matrix that is applied to each color if it is set. Adjusting brightness is just performing a translate on the color data, and contrast is performing a scale on the color. Gamma is a whole different form of transform, but it’s included in ImageAttributes which accepts the ColorMatrix.

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);

这篇关于调整亮度对比度的图像和γ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆