gpt4 book ai didi

java - 无法从解析中解码图像

转载 作者:行者123 更新时间:2023-12-01 10:40:41 32 4
gpt4 key购买 nike

我正在尝试解码从解析中获得的图像,同时将其发送到另一个函数进行解密,但是我似乎无法正确解密文件,因为在解码行上我得到的字符串是null 因此没有什么可解码的,我如何检索解析文件并解密然后将其发送到解码。

我的解析函数

case R.id.decryptButton:


Intent i = getIntent();
image = i.getStringExtra("image");
progressDialog = ProgressDialog.show(SingleFileView.this, "",
"Downloading Image...", true);

// Locate the class table named "ImageUpload" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"NewFiles");

// Locate the objectId from the class
query.getInBackground(objectId,
new GetCallback<ParseObject>() {

public void done(ParseObject object,
ParseException e) {
// TODO Auto-generated method stub

// Locate the column named "ImageName" and set
// the string

final ParseFile fileObject = (ParseFile) object
.get("ImageFile");
fileObject
.getDataInBackground(new GetDataCallback() {
public void done(byte[] data,
ParseException e) {
if (e == null) {
Log.d("test",
"We've got data in data.");
// Decode the Byte[] into
// Bitmap
FileInputStream fis = null;
saveFile(data, "temp.jpeg");

try {
File xx = new File(Environment.getExternalStorageDirectory()+"/temp.jpeg");
fis = new FileInputStream(String.valueOf(data));
System.out.print(fileObject.getUrl());
System.out.print(fis);

} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
byte[] dmg = decrypt(key, fis);
Bitmap bmp = BitmapFactory
.decodeByteArray(
dmg, 0,
dmg.length);

// Get the ImageView from
// main.xml
ImageView image = (ImageView) findViewById(R.id.image);

// Set the Bitmap into the
// ImageView
image.setImageBitmap(bmp);

// Close progress dialog
progressDialog.dismiss();

} else {
Log.d("test",
"There was a problem downloading the data.");
}
}
});
}
});

我的解密和保存文件功能

private byte[] decrypt(byte[] skey, InputStream fis){

SecretKeySpec skeySpec = new SecretKeySpec(skey, "AES");
Cipher cipher;
byte[] decryptedData=null;
CipherInputStream cis=null;
try {
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(iv));
// Create CipherInputStream to read and decrypt the image data
cis = new CipherInputStream(fis, cipher);
// Write encrypted image data to ByteArrayOutputStream
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[2048];
while ((cis.read(data)) != -1) {
buffer.write(data);
}
buffer.flush();
decryptedData=buffer.toByteArray();

}catch(Exception e){
e.printStackTrace();
}
finally{
try {
fis.close();
cis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return decryptedData;
}
public void saveFile(byte[] data, String outFileName){
FileOutputStream fos=null;
try {
fos=new FileOutputStream(Environment.getExternalStorageDirectory()+File.separator+outFileName);
fos.write(data);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

我似乎没有找到该文件的问题,因为我不确定问题是否出在解密方法上,或者我从解析中获取的文件是否正确完成。

最佳答案

错误是:“字符串为空,因此无法解码”,这表示没有输入,这就是要查看的内容。 IOW、调试、断点、调试器中的单次浸泡、打印变量。

关于java - 无法从解析中解码图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34426681/

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