gpt4 book ai didi

java - 隐写术尝试,为什么我的照片没有任何反应?

转载 作者:行者123 更新时间:2023-11-30 02:20:30 25 4
gpt4 key购买 nike

我正在尝试向用户手机上保存的图像写一条消息,基本上我的应用程序应该做的是,将 ImageView 设置为我刚刚创建的 View ,(我将其设置为将 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))

关于java - 隐写术尝试,为什么我的照片没有任何反应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28608603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com