您好我正在创建一个项目,部分内容我想将一条消息(用户键入的内容)编码为用户在他/她手机上的图像。 不过我是新手,并且我很难找到有关Android的隐写术资源。 所以我的问题是基本原理/方法是什么,或者我需要做什么才能将字符串编码成图像? 谢谢!
几乎正常工作,但编码正确,当我尝试将字符转换为值时,如果它的符号为0,则转换为-1。
代码: -
编码: -
public void encodeImg(ImageView imgEncrypt){
String test = "hello";
Bitmap bmap;
BitmapDrawable bmapD = (BitmapDrawable)imgEncrypt.getDrawable();
bmap = bmapD.getBitmap();
Bitmap operation = Bitmap.createBitmap(bmap.getWidth(),bmap.getHeight(),bmap.getConfig());
for(int i=0; i<bmap.getWidth(); i++){
for(int j=0; j<bmap.getHeight();j++){
int p = bmap.getPixel(i, j);
int r = Color.red(p);
int g = Color.green(p);
int b = Color.blue(p);
int alpha = Color.alpha(p);
if( i < 1 && j < 5 ){
int value = Character.getNumericValue(test.charAt(j));
alpha = value;
Log.w("myApp", "code has executed");
operation.setPixel(i, j, Color.argb(alpha, r, g, b));
}
}
}
imgEncrypt.setImageBitmap(operation);
Save savefile = new Save();
savefile.SaveImage(this, operation);
}
解码: -
public void decodeImg(ImageView imgEncrypt){
String message = "";
TextView hiddenMessage = (TextView) findViewById(R.id.hiddenMsg);
Bitmap bmap;
BitmapDrawable bmapD = (BitmapDrawable)imgEncrypt.getDrawable();
bmap = bmapD.getBitmap();
Bitmap operation = Bitmap.createBitmap(bmap.getWidth(),bmap.getHeight(),bmap.getConfig());
for(int i=0; i<bmap.getWidth(); i++){
for(int j=0; j<bmap.getHeight();j++){
int p = bmap.getPixel(i, j);
int r = Color.red(p);
int g = Color.green(p);
int b = Color.blue(p);
int alpha = Color.alpha(p);
if( i < 1 && j < 5 ){
int value = alpha;
char c = (char) value;
message += c;
Log.w("myApp", "code has executed");
}
}
}
hiddenMessage.setText(message);
}
}