Exemplo n.º 1
0
        /// <summary>  
                 /// 開始讀取數據  
                 /// </summary>  
                 /// <param name="p_Bytes">PCX文件訊息</param>  
        private void Load(byte[] p_Bytes)
        {
            byte[] _Bytes = p_Bytes;
            data = p_Bytes;
            if (_Bytes[0] != 0x0A)
            {
                return;
            }
            m_Head      = new PCXHEAD(_Bytes);
            m_ReadIndex = 128;
            PixelFormat _PixFormate = PixelFormat.Format24bppRgb;

            if (m_Head.Colour_Planes == 1)
            {
                switch (m_Head.Bits_Per_Pixel)
                {
                case 8:
                    _PixFormate = PixelFormat.Format8bppIndexed;
                    break;

                case 1:
                    _PixFormate = PixelFormat.Format1bppIndexed;
                    break;
                }
            }

            m_Image = new Bitmap(m_Head.Width, m_Head.Height, _PixFormate);
            BitmapData _Data = m_Image.LockBits(new Rectangle(0, 0, m_Image.Width, m_Image.Height), ImageLockMode.ReadWrite, _PixFormate);

            byte[] _BmpData = new byte[_Data.Stride * _Data.Height];

            for (int i = 0; i != m_Head.Height; i++)
            {
                byte[] _RowColorValue = new byte[0];
                switch (m_Head.Colour_Planes)
                {
                case 3:     //24位  
                                                _RowColorValue = LoadPCXLine24(_Bytes);
                    break;

                case 1:     //256色  
                                            switch(m_Head.Bits_Per_Pixel)
                    {
                    case 8:
                        _RowColorValue = LoadPCXLine8(_Bytes);
                        break;

                    case 1:
                        _RowColorValue = LoadPCXLine1(_Bytes);
                        break;
                    }

                    break;
                }
                int _Count = _RowColorValue.Length;
                Array.Copy(_RowColorValue, 0, _BmpData, i * _Data.Stride, _Data.Stride);
            }
            Marshal.Copy(_BmpData, 0, _Data.Scan0, _BmpData.Length);
            m_Image.UnlockBits(_Data);

            switch (m_Head.Colour_Planes)
            {
            case 1:
                if (m_Head.Bits_Per_Pixel == 8)
                {
                    ColorPalette _Palette = m_Image.Palette;
                    m_ReadIndex = p_Bytes.Length - 256 * 3;
                    for (int i = 0; i != 256; i++)
                    {
                        _Palette.Entries[i] = Color.FromArgb(p_Bytes[m_ReadIndex], p_Bytes[m_ReadIndex + 1], p_Bytes[m_ReadIndex + 2]);
                        m_ReadIndex        += 3;
                    }
                    m_Image.Palette = _Palette;
                }
                break;
            }
        }
Exemplo n.º 2
0
 public void getHeader()
 {
     header = m_Head;
 }