保存位图时Alpha值不会持久存在

时间:2013-04-18 08:24:15

标签: c# .net

早上好,

我正在为大学制作一个图像隐写术项目。 同时隐藏图像中的数据。我正在编写“文本长度”,它是像素中的Int32。因为Int32是4个字节。我想我可以在Alpha,Red,Green,Blue的4个字节中写出它,因为每种颜色都是1个字节。 然后我以bmp格式保存图像。 我使用单步执行和数据获取正确分布并在像素中设置。

当我回读像素时出现问题。 R,G,B有我们设定它们的价值。但无论它设置的是什么,alpha总是255。

我用于将Int32分配为4个字节的代码是

byte R, G, B, A;
int colorValue = messageLength;
int first = colorValue & 255;
//R contains bit 0-7 means the least significant 8 bits
R = (byte)first;
colorValue = colorValue - first;
int second = colorValue & 65535;
colorValue = colorValue - second;
second = second >> 8;
//G contains 8-15
G = (byte)second;
int third = colorValue & 16777215;
colorValue = colorValue - third;
third = third >> 16;
//B contains 16-23
B = (byte)third;
colorValue = colorValue >> 24;
//A contains 24-31
A = (byte)colorValue;
pixelColor = Color.FromArgb(A, R, G, B);
bitmap.SetPixel(location.X, location.Y, pixelColor);

获取值的代码是

byte R, G, B, A;
R = pixelColor.R;
G = pixelColor.G;
B = pixelColor.B;
A = pixelColor.A;

messageLength = A;
messageLength = messageLength << 8;
messageLength += B;
messageLength = messageLength << 8;
messageLength += G;
messageLength = messageLength << 8;
messageLength += R;

我有什么遗失的东西。是BMP不允许alpha值持续??? 请帮忙。 感谢。

1 个答案:

答案 0 :(得分:1)

很抱歉,Bitmap不支持alpha值。