Android : Need to pass a compressed image for encryption in Android

on Thursday, April 2, 2015


We are building an application which picks an image from the gallery displays it in imageView. When the encrypt button is pressed it is passed to a java class where it gets encrypted and is stored in the memory. I want to compress the image before encrypting. I am using Bitmap.scaledimage but I dont know exactly where to add it


Code for picking the image:



public void onClick(View v)
{
Intent i= new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,SELECTED_PICTURE);
}
});


code for displaying the image:



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;


code for encrypting:



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");
}
}
});


File x is declared like this:



final File x=new File(android.os.Environment.getExternalStorageDirectory(),File.separator+"Image");
x.mkdirs();


FilePath is string.


I want to know where I can add the image compression (what part of the code). Image compression we need bitmap but throughout I am working with uri, files and string for storing and displaying.


0 comments:

Post a Comment