急求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 * j + 1] = cl[index1].G;
bp2[i * DestStride + 3 * j + 2] = cl[index1].R;
j++;
bp2[i * DestStride + 3 * j] = cl[index2].B;
bp2[i * DestStride + 3 * j + 1] = cl[index2].G;
bp2[i * DestStride + 3 * j + 2] = cl[index2].R;
index++;
}
}
newbmp.UnlockBits(data2);
return newbmp;
}
}
private static byte[] GetBmp24BitColorValue(Bitmap bmp)
{
int width = bmp.Width;
int height = bmp.Height;
Bitmap bitmap_oldCopy =bmp;
BitmapData oldcopyBmpdata = null;
try
{
Rectangle rect = new Rectangle(0, 0, width, height);
oldcopyBmpdata = bitmap_oldCopy.LockBits(rect, ImageLockMode.ReadWrite, bitmap_oldCopy.PixelFormat);
IntPtr ptrOldCopy = oldcopyBmpdata.Scan0;
int oldBitmapDataLength = oldcopyBmpdata.Stride * height;
byte[] oldBmpValues = new byte[oldBitmapDataLength];
System.Runtime.InteropServices.Marshal.Copy(ptrOldCopy, oldBmpValues, 0, oldBitmapDataLength);
return oldBmpValues;
}
finally
{
if (oldcopyBmpdata != null)
{
bitmap_oldCopy.UnlockBits(oldcopyBmpdata);
}
}
}
[解决办法]
这个我也没办法,等版主来帮楼主看下吧
[解决办法]
如果没有人愿意免费帮你搞定,本人可以有偿给你写这个代码。