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

  • 常规讨论

  • //对比度调整
    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;
       }

    新手上路,大神指点!

    2012年8月22日 2:50

全部回复