C# 迭代位图行和列
我知道这可能很容易,但我找不到解决办法 在使用了当前位图的所有位图之后,我需要获得下一行位图 我正在制作一个速记程序,在图像中隐藏一个文本文件。 每个字符存储在8个不同的字节中。 所以在第一列中隐藏文本后,我需要得到下一列,依此类推。 我在这方面很弱。我尝试了第一行,但不知道其他行根据文本长度C# 迭代位图行和列,c#,bitmap,steganography,C#,Bitmap,Steganography,我知道这可能很容易,但我找不到解决办法 在使用了当前位图的所有位图之后,我需要获得下一行位图 我正在制作一个速记程序,在图像中隐藏一个文本文件。 每个字符存储在8个不同的字节中。 所以在第一列中隐藏文本后,我需要得到下一列,依此类推。 我在这方面很弱。我尝试了第一行,但不知道其他行根据文本长度 private void HIDE(){ if (textBox1.Text != "") { Bi
private void HIDE(){
if (textBox1.Text != "")
{
Bitmap bitmap = (Bitmap)pictureBox1.Image;
int next,width=0;
for (int t = 0; t < textBox1.Text.Length; t++)
{
next = 8 * t;
for (int i = 0; i < 8; i++)
{
if (i * t <= bitmap.Width/8)
{
//hiding code for 1st row
}
else
{
//hiding code for 2nd row
}
}
}
}}
private void HIDE(){
如果(textBox1.Text!=“”)
{
位图位图=(位图)pictureBox1.Image;
int next,宽度=0;
for(int t=0;t
private void HIDE(){
if (textBox1.Text != "")
{
Bitmap bitmap = (Bitmap)pictureBox1.Image;
// Starting point for embedding secret
int x0=0, y0=0;
// Error checking, to see if text can fit in image
int imageSize = bitmap.Width * bitmap.Height;
if (imageSize - x0 * bitmap.Width - y0 < 8 * textBox1.Text.Length)
{
// Deal with error
}
// Ready to embed
for (int t = 0; t < textBox1.Text.Length; t++)
{
for (int i = 0; i < 8; i++)
{
// Check if y0 has exceeded image width
// so to wrap around to the new row
if (y0 == bitmap.Width)
{
x0++;
y0=0;
}
// x0, y0 are now the current pixel coordinates
//
// EMBED MESSAGE HERE
//
y0++; // Move to the next pixel for the next bit
}
}
}}
对于文本“Hello World”,二进制将是0000000000000000000 1011000。现在,您可以将它们嵌入32个特定像素以及之后的实际秘密消息中。请记住,在这种情况下,您的图像必须至少具有8*TextBox1.text.Length+32
像素数才能容纳整个秘密
最重要的是,考虑到图像大小的限制,使用4字节作为文本长度是一种过分的做法。如果您始终能够保证文本大小不会超过特定长度,或者使用更动态的方法,例如
参考:整数到二进制字符串的转换借用自。相关:可能的重复非常感谢。我有隐藏代码。唯一困扰我的是公式。谢谢你。
int secretLength = 8 * textBox1.Text.Length;
string binary = Convert.ToString(secretLength, 2);