Re paste a complete code:
private void Adjust(Bitmap pBitmap, params int[] pValues)
{
Prepare(pValues);
BitmapData pBitmapData = pBitmap.LockBits(
new Rectangle(0, 0, pBitmap.Width, pBitmap.Height),
ImageLockMode.ReadWrite,
PixelFormat.Format24bppRgb);
byte[] pData = new byte[pBitmapData.Stride * pBitmapData.Height];
Marshal.Copy(pBitmapData.Scan0, pData, 0, pData.Length);
int iOffset = pBitmapData.Stride - pBitmapData.Width * 3;
int iIndex = 0;
for (int i = 0; i < pBitmapData.Height; i++)
{
for (int j = 0; j < pBitmapData.Width; j++)
{
for (int k = iIndex; k < iIndex + 3; k++)
{
pData[k] = Adjust(pData[k], k);
}
iIndex += 3;
}
iIndex += iOffset;
}
Marshal.Copy(pData, 0, pBitmapData.Scan0, pData.Length);
}
protected void Prepare(int[] pValues)
{
m_iRed = pValues[0];
m_iGreen = pValues[1];
m_iBlue = pValues[2];
}
protected byte Adjust(byte iValue, int iIndex)
{
int nColour = 0;
switch (iIndex % 3)
{
case 0:
nColour = (int)iValue + m_iBlue;
break;
case 1:
nColour = (int)iValue + m_iGreen;
break;
case 2:
nColour = (int)iValue + m_iRed;
break;
}
return Fix(nColour);
}
protected byte Fix(int iValue)
{
if (iValue < 0) iValue = 0;
if (iValue > 255) iValue = 255;
return (byte)iValue;
}
What I have tried:
i have a picture is divided into four parts.i want change color by RGB.but only changed half.
1.change failed when width of the picture less than 256.
2.my small picture maximum not more than 256.
3.Every picture of 256*256 is normal.
4.Problem parameter:r=0,g=0,b=52.
Sorry, I don't know how to reply downstairs.
about Ralf Meier's solution
On change pixel loop, I debug, the color of the picture and did not change the picture, they are the same value.
about Jochen Arndt's solution
At that time, the code did not paste completely, for the calculation of the value I have been repaired by Fix.
Changed to absolute value, still no effect.
At the moment, I still haven't found the problem.
the image does not change color when set r=0,g=0,b=52:https://i.stack.imgur.com/IIrgd.jpg