隐写术尝试,为什么我的照片没有任何反应?
Steganography attempt, why is nothing happening to my picture?
我正在尝试向保存在用户 phone 上的图像写一条消息,基本上我的应用程序应该做的是,将图像视图设置为我刚刚创建的视图,(我将它设置为将 100 添加到其他像素,以便我可以判断)但是这并没有发生,我希望你能告诉我为什么以及如何修复它。谢谢!
代码:
public class EncryptImg extends ActionBarActivity implements OnClickListener{
private static int LOAD_IMAGE_RESULTS = 1;
ImageView imgEncrypt;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.encryptimg);
Button galleryBrowse = (Button) findViewById(R.id.browseGallerybtn1);
galleryBrowse.setOnClickListener(this); /*Set OnClickListener to listen for the galerryBrowse button*/
Button encodeImage = (Button) findViewById(R.id.encodeBtn);
encodeImage.setOnClickListener(this); /* Set OnClickListener for the encodeBtn button */
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.browseGallerybtn1){
Intent loadImgIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(loadImgIntent, LOAD_IMAGE_RESULTS);
if(v.getId() == R.id.encodeBtn){
encodeImg(imgEncrypt);
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
imgEncrypt = (ImageView) findViewById(R.id.encryptImgView);
// http://www.itcuties.com/android/pick-image-from-gallery/.
if (requestCode == LOAD_IMAGE_RESULTS && resultCode == RESULT_OK && data != null) {
// Let's read picked image data - its URI
Uri pickedImage = data.getData();
// Let's read picked image path using content resolver
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
cursor.moveToFirst();
String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
// Now we need to set the GUI ImageView data with data read from the picked file.
imgEncrypt.setImageBitmap(BitmapFactory.decodeFile(imagePath));
// At the end remember to close the cursor or you will end with the RuntimeException!
cursor.close();
}
}
/*Added code */
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<5;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);
int value = Character.getNumericValue(test.charAt(i));
r = 100 + r;
g = 100 + g;
b = 100 + b;
Log.w("myApp", "code has executed");
alpha = value;
operation.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
}
}
imgEncrypt.setImageBitmap(operation);
}
}
XML:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/browseGallerybtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:layout_marginTop="20dp"
android:text="Browse Gallery" />
<ImageView
android:id="@+id/encryptImgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/encodeBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="14dp"
android:text="Encode!" />
您永远不会使用修改后的 alpha
值:
alpha = value; // your modified value
operation.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
^^^^^^^^^^^^^---the original alpha
您可能需要 .setPixel(i, j, Color.argb(alpha, r, g, b))
。
我正在尝试向保存在用户 phone 上的图像写一条消息,基本上我的应用程序应该做的是,将图像视图设置为我刚刚创建的视图,(我将它设置为将 100 添加到其他像素,以便我可以判断)但是这并没有发生,我希望你能告诉我为什么以及如何修复它。谢谢!
代码:
public class EncryptImg extends ActionBarActivity implements OnClickListener{
private static int LOAD_IMAGE_RESULTS = 1;
ImageView imgEncrypt;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.encryptimg);
Button galleryBrowse = (Button) findViewById(R.id.browseGallerybtn1);
galleryBrowse.setOnClickListener(this); /*Set OnClickListener to listen for the galerryBrowse button*/
Button encodeImage = (Button) findViewById(R.id.encodeBtn);
encodeImage.setOnClickListener(this); /* Set OnClickListener for the encodeBtn button */
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.browseGallerybtn1){
Intent loadImgIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(loadImgIntent, LOAD_IMAGE_RESULTS);
if(v.getId() == R.id.encodeBtn){
encodeImg(imgEncrypt);
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
imgEncrypt = (ImageView) findViewById(R.id.encryptImgView);
// http://www.itcuties.com/android/pick-image-from-gallery/.
if (requestCode == LOAD_IMAGE_RESULTS && resultCode == RESULT_OK && data != null) {
// Let's read picked image data - its URI
Uri pickedImage = data.getData();
// Let's read picked image path using content resolver
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
cursor.moveToFirst();
String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
// Now we need to set the GUI ImageView data with data read from the picked file.
imgEncrypt.setImageBitmap(BitmapFactory.decodeFile(imagePath));
// At the end remember to close the cursor or you will end with the RuntimeException!
cursor.close();
}
}
/*Added code */
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<5;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);
int value = Character.getNumericValue(test.charAt(i));
r = 100 + r;
g = 100 + g;
b = 100 + b;
Log.w("myApp", "code has executed");
alpha = value;
operation.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
}
}
imgEncrypt.setImageBitmap(operation);
}
}
XML:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/browseGallerybtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:layout_marginTop="20dp"
android:text="Browse Gallery" />
<ImageView
android:id="@+id/encryptImgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/encodeBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="14dp"
android:text="Encode!" />
您永远不会使用修改后的 alpha
值:
alpha = value; // your modified value
operation.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
^^^^^^^^^^^^^---the original alpha
您可能需要 .setPixel(i, j, Color.argb(alpha, r, g, b))
。