Image 类有个 PixelFormat 属性可以指定位深度,如果不指定,默认就是 32 位的,应该设置为 System.Drawing.Imaging.PixelFormat.Format8bppIndexed 值。
但这个属性是只读的,只能在实例化时指定。
建议先实例化一个 Bitmap(Bitmap 类是继承自 Image 类的),有一种构造方法是 Bitmap(int, int System.Drawing.Imaging.PixelFormat)。然后将你的图片先绘制到新的 Bitmap 对象上,再保存。
不过据说 Image.Save() 方法有个 Bug,具体分析和解决方案参考:http://bbs.csdn.net/topics/330223763
我用你的代码试了一下 好使.
byte[] photo = null;
MemoryStream ms = new MemoryStream();
Bitmap bmp = new Bitmap(pb.Image);
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
photo = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo, 0, Convert.ToInt32(ms.Length));
bmp.Dispose();
MemoryStream ms1 = new MemoryStream(photo);
Image img = Image.FromStream(ms1);
img.Save(@"C:\Users\samsung\Desktop\new1.bmp");
原BMP 1.bmp 48*30 4.27KB
新BMP new1.bmp 48*30 5.67KB
参考
http://blog.csdn.net/azkabannull/article/details/7770157
设置一下Image的PixelFormat属性,将其值设置为Format8bppIndexed
是不是对图片做修改了