日期:2014-05-17  浏览次数:20900 次

急求4bit位图转化成24bit位图(彩色的)
本人初学c#关于图像处理方面的内容,请各位大神指教,这个程序为什么出来的图像结果总是不对?
public Bitmap ConvertToBitmap24(Bitmap bmp)
        {
            unsafe
            {
                int Width = bmp.Width;
                int Height = bmp.Height;
                Bitmap newbmp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format24bppRgb);
                BitmapData data = new BitmapData();             
                BitmapData data2 = new BitmapData();
                newbmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb, data2);
                byte* bp2 = (byte*)data2.Scan0.ToPointer();
                int DestStride = Width;
                int stride = Width / 2; 
                int index=0;
                byte[] new4IndexBmpdataValues = GetBmp24BitColorValue(bmp); 
                for (int i = 0; i != Height; i++)
                {
                    for (int j = 0; j != Width; j++)
                    {                                
                        int index1 = (int)((byte)(new4IndexBmpdataValues[index] >> 4) & 0x0F);
                        int index2 = (int)(new4IndexBmpdataValues[index] & 0x0F);
                        bp2[i * DestStride + 3 * j] = cl[index1].B;
                        bp2[i * DestStride + 3&nbs