public byte[] Rgb2Gray(Bitmap temp) { bool bRet = false; int nWidth = temp.Width; int nHeight = temp.Height; int nDeep = temp.PixelFormat == PixelFormat.Format8bppIndexed ? 1 : (temp.PixelFormat == PixelFormat.Format32bppRgb || temp.PixelFormat == PixelFormat.Format32bppArgb || temp.PixelFormat == PixelFormat.Format32bppPArgb) ? 4 : 3; byte[] byBuffer = new byte[(uint)nWidth * (uint)nHeight * nDeep]; byte[] byBufferY = new byte[(uint)nWidth * (uint)nHeight * 1]; if (temp.PixelFormat == PixelFormat.Format24bppRgb || temp.PixelFormat == PixelFormat.Format32bppRgb || temp.PixelFormat == PixelFormat.Format32bppArgb || temp.PixelFormat == PixelFormat.Format32bppPArgb ) { byBuffer = ImageChangeHelper.Instance.ConvertBitmapToByteArray(temp); ImageConvert ic = new ImageConvert(); ic.BGR_To_Y(byBuffer, byBufferY, (uint)nWidth, (uint)nHeight); } else { byBufferY = ImageChangeHelper.Instance.ConvertBitmapToByteArray(temp); } return(byBufferY); }
public override bool BufToByteGray(int nID, byte[] _FrameBuffer, byte[] buf) { ImageConvert ToImageConverRTV24 = new ImageConvert(); bool result = ToImageConverRTV24.BGR_To_Y(_FrameBuffer, buf, (UInt32)CamDeviceList[nID].GetWidth(), (UInt32)CamDeviceList[nID].GetHeight()); return(result); }