朋友,我现在正在使用图像隐写术。为此,我需要将图像转换为位数组并将其解码。但是,当我尝试将图像转换回其原始形状时,它在我的ImageView中只显示黑色。这里是我的代码我的图片在android中为黑色
btnEncode =(按钮)findViewById(R.id.encode); btnEncode.setOnClickListener(新View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//imgPath.setText(imageToBase64(selectedImagePath));
ImageView imageView=(ImageView)findViewById(R.id.imageView1);
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
bytes = getBytesFromBitmap(bitmap);
StringBuilder binary = new StringBuilder();
for (byte b : bytes)
{
int val = b;
for (int i = 0; i < 8; i++)
{
binary.append((val & 128) == 0 ? 0 : 1);
val <<= 1;
}
binary.append(' ');
}
//To save the binary in newString
String ImageEncoded=new String(binary.toString());
TextView imgData=(TextView)findViewById(R.id.txtResult);
imgData.setText(ImageEncoded);
}
});
btnDecode = (Button) findViewById(R.id.decode);
btnDecode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
ImageView imageView=(ImageView)findViewById(R.id.imageView1);
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
bytes = getBytesFromBitmap(bitmap);
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
ImageView image = (ImageView) findViewById(R.id.imageView2);
image.setImageBitmap(bmp);
}
});
public static byte[] getBytesFromBitmap(Bitmap bitmap)
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 70, stream);
return stream.toByteArray();
}
为什么转换是必需的? – Triode
也许你有CompressFormat.JPEG,那把你的透明度黑色使用所需的PNG代替 – JRowan
转换,这样我可以隐藏图像在一个秘密的短信..你觉得我可以用任何其他方式 – Abinthaha