询问者
求大神帮我看一下对比度调整的算法。在24位的图像中每个像素占3字节,每行是4字节吗?

常规讨论
-
//对比度调整
private: System::Void hScrollBar5_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e)
{
int cdegree;
cdegree = hScrollBar5->Value;
label13->Text = cdegree.ToString();
if (cdegree < -100) cdegree = -100;
if (cdegree > 100) cdegree = 100;
double pixel = 0;
double contrast = (100.0 + cdegree) / 100.0;
contrast *= contrast;
int w = bitmap->Width;
int h = bitmap->Height;
//锁定位图对象至内存,存为24位
Rectangle rt = Rectangle(0,0,w,h);
System::Drawing::Imaging::BitmapData^ srcData = bitmap->LockBits(rt,ImageLockMode::ReadWrite,bitmap->PixelFormat);
IntPtr p = srcData->Scan0; //获取第一行开头的地址
//用一个数组来存储位图的字节
int bytes = Math::Abs(srcData->Stride) * h;
array<Byte>^rgbValues = gcnew array<Byte>(bytes);
//把RGB的值都复制到该数组中
System::Runtime::InteropServices::Marshal::Copy( p, rgbValues, 0, bytes );
// 处理指定位置像素的对比度
for (int counter = 0; counter<rgbValues->Length; counter=counter+3)
for(int i=counter;i<=counter+2;i++)
{
pixel = ((rgbValues[i] / 255.0- 0.5) * contrast + 0.5) * 255;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
rgbValues[i] = (Byte)pixel;
}
//把新的RGB值复制回位图中
System::Runtime::InteropServices::Marshal::Copy( rgbValues, 0, p, bytes );
//解锁位图
bitmap->UnlockBits(srcData);
pictureBox1->Image = bitmap;
}新手上路,大神指点!
- 已更改类型 Damon ZhengModerator 2012年8月29日 11:35
全部回复
-
-
您好,
首先,非常感谢您的积极参与。
根据您的描述,您的问题没有固定的答案。所以我认为将这个帖子的类型改为“常规讨论”会更好一些。
谢谢您的理解。
Damon Zheng [MSFT]
MSDN Community Support | Feedback to us
- 已编辑 Damon ZhengModerator 2012年8月29日 11:57