none
对一张分成四份的图片改变颜色,但是只改变了1/2. RRS feed

  • 问题

  • 使用了bitmapdata来处理,用内存法来实现,但是四张图片只有2张变色 2张未变,同样的代码。

    向同样做过图片处理的同仁求助

     private void Adjust(Bitmap pBitmap, params int[] 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);
                pBitmap.UnlockBits(pBitmapData);
    
                
            }
    
     protected override 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);
            }

    2017年2月15日 3:26

全部回复

  • 你好,

    你可以提供完整的代码和相关的图片吗? 以便我能我的机器上重现你的问题。

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    2017年2月17日 8:38
    版主