【发布时间】:2015-05-16 03:17:34
【问题描述】:
我编写了一个代码来修改 PNG 图像的每个像素的最低有效位,然后将图像保存在外部存储器中。现在,当我打开 PNG 图像时,我不知道如何进行反向操作,这意味着我不知道如何从这些位中获取字符串。有人可以解释一下吗?谢谢。
这是在最低有效节拍中插入字符串的代码。
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode)
{
case FILE_SELECT_CODE:
if(resultCode==RESULT_OK)
{
Uri uri2 = data.getData();
String[] proj = {MediaStore.Images.Media.DATA};
CursorLoader cursorLoader = new CursorLoader(this,uri2,proj,null,null,null);
Cursor cursor = cursorLoader.loadInBackground();
int column_index=cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String uri = cursor.getString(column_index);
Bitmap img = BitmapFactory.decodeFile(uri);
int height = img.getHeight();
int width = img.getWidth();
int[] pixel = new int[height * width];
img.getPixels(pixel, 0, width, 1, 1, width - 1, height - 1);
String key = "prova";
byte[] b = key.getBytes();
int count = 0;
for (byte current_byte : b) {
for (int j = 7; j >= 0; j--) {
int lsb = (current_byte >> j) & 1;
pixel[count] = (pixel[count] & 0xfffffffe) + lsb;
count++;
}
}
Bitmap newImg = Bitmap.createBitmap(pixel,0,width, width-1,height-1, Bitmap.Config.ARGB_8888);
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(newImg);
setContentView(imageView);
String filename = "myimage.png";
File file2 = new File(getExternalFilesDir(null), filename);
try
{
FileOutputStream fileOutputStream = new FileOutputStream(file2);
newImg.compress(Bitmap.CompressFormat.PNG,100,fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
break;
}
}
以下是从该位读取字符串的代码的开头。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
Uri uri2 = intent.getData();
String[] proj = {MediaStore.Images.Media.DATA};
CursorLoader cursorLoader = new CursorLoader(this,uri2,proj,null,null,null);
Cursor cursor = cursorLoader.loadInBackground();
int column_index=cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String uri = cursor.getString(column_index);
Bitmap img = BitmapFactory.decodeFile(uri);
int height = img.getHeight();
int width = img.getWidth();
int[] pixel = new int[height * width];
img.getPixels(pixel, 0, width, 1, 1, width - 1, height - 1);
在这部分的最后,我从图像中获取了像素数组,我必须使用它从最不重要的节拍中获取字符串。
PS:我不能使用 BufferedImage。
【问题讨论】:
-
如果你正在做速记算法,只需使用 Alpha 通道来存储字符(仅限 ASCII 0-255)。
-
对不起,我不知道你在说什么。你能解释一下怎么做吗?
-
您正试图在图像中隐藏文本。不是吗?
-
是的,完全正确。我正在这样做。
-
所以,使用图像透明度(不太明显)。但是你可以使用的字符是有限的:ASCII 0-255,而不是 Unicode。
标签: java android image steganography