gpt4 book ai didi

java - 无法提取隐写术中的文本

转载 作者:行者123 更新时间:2023-12-01 12:48:22 24 4
gpt4 key购买 nike

我有一个代码,可以使用此处的代码在 C# 中使用速记将字符串值放在图像上

http://www.codeproject.com/Tips/635715/Steganography-Simple-Implementation-in-Csharp

现在我必须在 Android 端提取字符串。这是我用于文本提取的 Android 端代码

   private String extractText(Bitmap bmp) {
// TODO Auto-generated method stub
int colorUnitIndex = 0;
int charValue = 0;

// holds the text that will be extracted from the image
String extractedText ="";

for(int w=0;w<bmp.getHeight();w++)
{
for(int h=0;h<bmp.getWidth();h++)
{
int color=bmp.getPixel(h, w);
green=Color.green(color);
blue=Color.blue(color);
red=Color.red(color);

bred=(byte)red;
bgreen=(byte)green;
bblue=(byte)blue;

// for each pixel, pass through its elements (RGB)
for (int n = 0; n < 3; n++)
{
switch (colorUnitIndex % 3)
{
case 0:
{
// get the LSB from the pixel element (will be pixel.R % 2)
// then add one bit to the right of the current character
// this can be done by (charValue = charValue * 2)
// replace the added bit (which value is by default 0) with
// the LSB of the pixel element, simply by addition
charValue = charValue * 2 + bred % 2;
} break;
case 1:
{
charValue = charValue * 2 + bgreen % 2;
} break;
case 2:
{
charValue = charValue * 2 + bblue % 2;
} break;
}

colorUnitIndex++;

// if 8 bits has been added, then add the current character to the result text
if (colorUnitIndex % 8 == 0)
{
// reverse? of course, since each time the process happens on the right (for simplicity)
charValue = reverseBits(charValue);

// can only be 0 if it is the stop character (the 8 zeros)
if (charValue == 0)
{
return extractedText;
}

// convert the character value from int to char
char c = (char)charValue;

// add the current character to the result text
extractedText += String.valueOf(c);
}
}

}

}
return extractedText;


}

private int reverseBits(int n) {
// TODO Auto-generated method stub


int result = 0;

for (int i = 0; i < 8; i++)
{
result = result * 2 + n % 2;

n /= 2;
}

return result;
}

};

但我在 Android 端没有得到正确的字符串。不知道是什么问题。任何人都可以帮忙吗?提前致谢。

最佳答案

终于找到解决办法了只需在每个位的循环上使用此代码,我就可以提取文本。

               result[b] = (byte)((result[b] << 1) | (buff[offset] & 1));

谢谢大家。

关于java - 无法提取隐写术中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24464349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com