【发布时间】:2013-04-18 08:24:14
【问题描述】:
大家早上好,
我正在为大学做一个图像隐写术项目。 在图像中隐藏数据时。我正在写“文本长度”,它是一个像素中的 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 值持续存在??? 请帮忙。 谢谢。
【问题讨论】:
-
如果不查看用于编写和读取位图的代码,就很难诊断问题。可以发一下吗?
-
不确定,因此是评论,但您不需要诸如
PNG之类的东西来保存 alpha 值吗? -
似乎不可能。也许use PNG?
-
我只是想确认使用 Bitmap.MakeTransparent() 和 Bitmap.Save(sFilePath, ImageFormat.Png) 可以保留 alpha 值。