Java 隐写术尝试,为什么我的照片什么都没发生?
我正在尝试向用户手机上保存的图像发送消息,我的应用程序应该做的基本上是,将图像视图设置为我刚刚创建的图像视图(我将其设置为在其他像素上添加100,以便我可以知道),但这没有发生,我希望您能告诉我为什么以及如何修复它。谢谢 代码:Java 隐写术尝试,为什么我的照片什么都没发生?,java,android,imageview,steganography,Java,Android,Imageview,Steganography,我正在尝试向用户手机上保存的图像发送消息,我的应用程序应该做的基本上是,将图像视图设置为我刚刚创建的图像视图(我将其设置为在其他像素上添加100,以便我可以知道),但这没有发生,我希望您能告诉我为什么以及如何修复它。谢谢 代码: 公共类EncryptImg扩展ActionBarActivity实现OnClickListener{ 私有静态整型加载\图像\结果=1; ImageView imgEncrypt; @凌驾 创建时受保护的void(Bundle savedInstanceState){
公共类EncryptImg扩展ActionBarActivity实现OnClickListener{
私有静态整型加载\图像\结果=1;
ImageView imgEncrypt;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.encryptimg);
按钮galleryBrowse=(按钮)findViewById(R.id.browseGallerybtn1);
galleryBrowse.setOnClickListener(this);/*将OnClickListener设置为侦听galerryBrowse按钮*/
按钮编码图像=(按钮)findViewById(R.id.encodeBtn);
encodeImage.setOnClickListener(此);/*为encodeBtn按钮设置OnClickListener*/
}
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
if(v.getId()==R.id.browseGallerybtn1){
Intent loadImgIntent=newintent(Intent.ACTION\u PICK,android.provider.MediaStore.Images.Media.EXTERNAL\u CONTENT\u URI);
startActivityForResult(加载内容、加载图像结果);
if(v.getId()==R.id.encodeBtn){
编码img(imgEncrypt);
}
}
}
@凌驾
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
imgEncrypt=(ImageView)findViewById(R.id.encryptImgView);
// http://www.itcuties.com/android/pick-image-from-gallery/.
if(requestCode==LOAD\u IMAGE\u RESULTS&&resultCode==RESULT\u OK&&data!=null){
//让我们读取拾取的图像数据-其URI
Uri pickeImage=data.getData();
//让我们使用内容解析器读取拾取的图像路径
字符串[]文件路径={MediaStore.Images.Media.DATA};
Cursor Cursor=getContentResolver().query(pickeImage,filePath,null,null);
cursor.moveToFirst();
String imagePath=cursor.getString(cursor.getColumnIndex(filePath[0]);
//现在我们需要使用从拾取的文件读取的数据设置GUI ImageView数据。
imgEncrypt.setImageBitmap(BitmapFactory.decodeFile(imagePath));
//最后请记住关闭光标,否则将以RuntimeException结束!
cursor.close();
}
}
/*添加代码*/
公共无效编码img(ImageView imgEncrypt){
String test=“hello”;
位图bmap;
BitmapDrawable bmapD=(BitmapDrawable)imgEncrypt.getDrawable();
bmap=bmapD.getBitmap();
位图操作=Bitmap.createBitmap(bmap.getWidth(),bmap.getHeight(),bmap.getConfig());
对于(int i=0;i您从不使用修改后的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))
相反。噢,谢谢你这么做,但是,我不认为正在执行的代码没有显示日志消息。你会知道为什么吗?@Marc b可能是因为你的onclick是嵌套的。你的encodeImg调用不能发生,因为它在一个代码块中,可以处理你视图中其他按钮的点击。正确地缩进该代码块e区域,您将看到原因。哇,我怎么没有注意到,谢谢。很抱歉,现在我又出现了一个错误,我一单击该按钮,应用程序就会关闭://logcat说这是由于这一行----------------->“int value=Character.getNumericValue(test.charAt(I))“;”——————错误是“line,java.lang.StringIndexOutOfBoundsException:length=5;index=5”——————但我知道如何修复它,I
上升到bmap.Width,但你的文本字符串只有5个字符……也许你想要j
而改为5.omg我真是太感谢你了!先生太棒了!
<?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 = value; // your modified value
operation.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
^^^^^^^^^^^^^---the original alpha