我們正在構建一個應用程序,從圖庫中選取一個圖像,將其顯示在imageView中。當加密按鈕被按下時,它被傳遞給一個java類,它被加密並存儲在內存中。我想在加密之前壓縮圖像。我使用Bitmap.scaledimage,但我不知道究竟在何處添加它需要傳遞一個壓縮的圖像進行加密Android
代碼採摘圖像:
public void onClick(View v)
{
Intent i= new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,SELECTED_PICTURE);
}
});
代碼用於顯示圖像:
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
{
case SELECTED_PICTURE:
if(resultCode==RESULT_OK)
{
Uri uri= data.getData();
String[]projection= {MediaStore.Images.Media.DATA};
Cursor cursor= getContentResolver().query(uri, projection, null, null, null);
cursor.moveToFirst();
int columnIndex= cursor.getColumnIndex(projection[0]);
filePath= cursor.getString(columnIndex);
cursor.close();
iv.setImageBitmap(BitmapFactory.decodeFile(filePath));
}
break;
代碼加密:
one = (Button) findViewById(R.id.button2);
one.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try{
blowfish encryptFile = new blowfish("thisismypassword");
//destpath=Environment.getExternalStorageDirectory().getAbsolutePath()+nameoffolder;
destpath= x.getPath()+nameoffolder;
//destpath="/storage/sdcard/test";
encryptFile.encrypt(filePath,destpath);
Toast.makeText(Image.this,
"Done encrypting..yey..",
Toast.LENGTH_SHORT).show();
}catch (Exception e) {
Toast.makeText(Image.this, e.getMessage(),
Toast.LENGTH_SHORT).show();System.out.println("sells");
}
}
});
文件x聲明如下:
final File x=new File(android.os.Environment.getExternalStorageDirectory(),File.separator+"Image");
x.mkdirs();
FilePath是字符串。
我想知道我可以在哪裏添加圖像壓縮(代碼的哪一部分)。圖像壓縮我們需要位圖,但是我一直在使用uri,文件和字符串進行存儲和顯示。
您正在加密.jpg文件(在filePath中)。爲什麼要壓縮.jpg文件?這沒有帶來什麼。 – greenapps 2015-04-02 20:36:23
我們只是想在存儲時減小圖像的大小。感謝回覆。還有解密圖像的解密功能。我還沒有貼出代碼。我們希望解密後的圖像採用壓縮格式,以便節省大小 – Sowmya 2015-04-03 01:44:20
究竟是什麼問題。將代碼加載到Bitmap中然後更改分辨率(widthxheight)的代碼已在此網站上發佈多次。 '我們希望解密後的圖像是壓縮格式,以節省大小'。對不起,但我不明白你在說什麼。 – greenapps 2015-04-03 08:20:26