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.
public Bitmap decodeSampledBitmapFromUri(String uri, int reqWidth, int reqHeight) {
Bitmap bm = null;
try{
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(getContentResolver().openInputStream(Uri.parse(uri)), null, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeStream(getContentResolver().openInputStream(Uri.parse(uri)), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
return bm;
}
public int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height / (float)reqHeight);
} else {
inSampleSize = Math.round((float)width / (float)reqWidth);
}
}
return inSampleSize;
}
might be like this. may i see your full coding? i need your encrypt and decrypt part.
Related
I have this code that take photo and save to external storage, what I want is save to internal storage, please help me... what I should change to save to internal storage...
thank you
public class MainActivity extends AppCompatActivity {
public static final int CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE = 1777;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//Check that request code matches ours:
if (requestCode == CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE) {
//Get our saved file into a bitmap object:
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "image.jpg");
Bitmap bitmap = decodeSampledBitmapFromFile(file.getAbsolutePath(), 1000, 700);
}
}
public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight) {
//First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize, Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
options.inPreferredConfig = Bitmap.Config.RGB_565;
int inSampleSize = 1;
if (height > reqHeight) {
inSampleSize = Math.round((float) height / (float) reqHeight);
}
int expectedWidth = width / inSampleSize;
if (expectedWidth > reqWidth) {
//if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize..
inSampleSize = Math.round((float) width / (float) reqWidth);
}
options.inSampleSize = inSampleSize;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
}
You can try this code to save your image to internal storage:
FileOutputStream fos;
try {
fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
// You can also use .JPG
yourBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
}
catch (FileNotFoundException e) {
Log.e(TAG, e.getMessage());
}
catch (IOException e) {
Log.e(TAG, e.getMessage());
} finally {
fos.close();
}
You can also have a look at this: https://developer.android.com/guide/topics/data/data-storage.html#filesInternal
EDIT
For saving your full size image file to internal storage, you'll have to change your
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg");
to
File file = new File(context.getFilesDir(), "image.jpg");
getFilesDir() returns internal directory of your app. You will find more detailed information here: https://developer.android.com/training/basics/data-storage/files.html#WriteInternalStorage
I have a bunch of code that works fine when I'm not applying crop activity
but i wanted to apply crop to the selected image and send it to server using Rest API
TypedFile typedFile = new TypedFile("multipart/form-data",savedFileDestination);
initiateProgressDialog();
How to set cropped URI instead of savedFileDestination so that it takes cropped image path as file ?
Use the below method to crop:
public static Bitmap decodeSampledBitmapFromUri(String path, int reqWidth, int reqHeight) {
Bitmap bm = null;
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(path, options);
return bm;
}
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) reqHeight);
} else {
inSampleSize = Math.round((float) width / (float) reqWidth);
}
}
return inSampleSize;
}
Thanks For all your answers and comments I found my solution it was that i have to firstly store my croped image into a file diectory because the croped image stores in the cache memory and we need the file path and send the file path to server to store it..... Thanks again
On click of camera
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File outPutFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "Path of your custom directory);
if (!outPutFile.exists()) {
outPutFile.mkdirs();
}
Uri capturedImageUri = Uri.fromFile(File.createTempFile("Your app directory name" + System.currentTimeMillis(), ".jpg", outPutFile));
Logg.e(getClass().getSimpleName(), "Captured_Pic ===== " + Uri.fromFile(outPutFile));
intent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
startActivityForResult(intent, Util.REQUEST_CAMERA);
On click of Gallery
CropImage.startPickImageActivity(HomeActivity.this);
OnActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_CANCELED) {
switch (requestCode) {
case Util.REQUEST_CAMERA: // Camera request
startCropImageActivity(capturedImageUri);
break;
case CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE: // Crop
CropImage.ActivityResult result = CropImage.getActivityResult(data);
try {
if (resultCode == RESULT_OK) {
resultUri = result.getUri();
mProfileView.setImageURI(Uri.parse(resultUri.toString())); // this is my imageview, where I'll set that cropped image Uri.
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
} catch (Exception e) {
e.printStackTrace();
}
break;
case CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE: // Gallery request
try {
Uri selectedImageUri = CropImage.getPickImageResultUri(this, data);
startCropImageActivity(selectedImageUri);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
}
This method will set property to cropping image tool according to your requirement
private void startCropImageActivity(Uri imageUri) {
CropImage.activity(imageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.setCropShape(CropImageView.CropShape.RECTANGLE)
.setActivityMenuIconColor(ContextCompat.getColor(HomeActivity.this, R.color.app_blue))
.setGuidelinesColor(ContextCompat.getColor(HomeActivity.this, R.color.app_blue))
.setScaleType(CropImageView.ScaleType.FIT_CENTER)
.setFixAspectRatio(true)
.setBorderCornerColor(ContextCompat.getColor(HomeActivity.this, R.color.app_blue))
.setBorderLineColor(ContextCompat.getColor(HomeActivity.this, R.color.app_blue))
.start(this);
}
I use below code for ScreenShot:
public class startActivity{
Bitmap layoutBitmap = Bitmap.createBitmap(mReLayout.getWidth(), mReLayout.getHeight(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(layoutBitmap);
mReLayout.draw(canvas);
Uri uri = getImageUri(getApplicationContext(), layoutBitmap);
Intent mIntent = new Intent(CategoryActivity.this, MainActivity.class);
mIntent.putExtra(Constant.BYTE_IMAGE, uri.toString());
startActivity(mIntent);
}
MainActivity.class
private void setUpImageBitmap() {
Uri uri = Uri.parse(getIntent().getExtras().getString(Constant.BYTE_IMAGE));
String selectedImagePath = getPath(uri);
mImageCube.setImageBitmap(Utils.decodeSampledBitmapFromResource(selectedImagePath, 200, 200));
}
public String getPath(Uri uri) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
Class Utils
public static Bitmap decodeSampledBitmapFromResource(String resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(resId, options);
}
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 2;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) reqHeight);
} else {
inSampleSize = Math.round((float) width / (float) reqWidth);
}
}
return inSampleSize;
}
How can I take a screenshot without saving it in the gallery?
Here Below code for how to take screenshot for any android control, means ImageView or Layout. below code for ImageView.
ImageView iv = (ImageView) findViewById(R.id.imageView1);
View v1 = getWindow().getDecorView().getRootView();
// View v1 = iv.getRootView(); //even this works
// View v1 = findViewById(android.R.id.content); //this works too
// but gives only content
v1.setDrawingCacheEnabled(true);
myBitmap = v1.getDrawingCache();
saveBitmap(myBitmap);
saveBitmap(myBitmap);
public void saveBitmap(Bitmap bitmap) {
String filePath = Environment.getExternalStorageDirectory()
+ File.separator + "Pictures/screenshot.png";
String nomedia = Environment.getExternalStorageDirectory()
+ File.separator + "Pictures/.nomedia";
File nomediaFile= new File(nomedia);
if(!nomediaFile.exists()){
nomediaFile.createNewFile();
}
File imagePath = new File(filePath);
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
sendMail(filePath);
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
Now you dont want to show any images in gallery then you have to ceate .nomedia file in folder of screenshot save. see below code for that.
String nomedia = Environment.getExternalStorageDirectory()
+ File.separator + "Pictures/.nomedia";
File nomediaFile= new File(nomedia);
if(!nomediaFile.exists()){
nomediaFile.createNewFile();
}
Above code already implemented in saveBitmap() method. I think help you for you this...
Now you want to share this image then get path of image and share with below code.
public void shareImage(String path) {
Uri myUri = Uri.parse("file://" + path);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello");
shareIntent.putExtra(Intent.EXTRA_STREAM, myUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
}
The image files have to be stored somewhere. I think your actual question is how to hide image files from the gallery app.
To hide them from your gallery app there are two ways doing this:
1. Create a .nomedia file:
In the folder where you save your images (given by uri) you have to create a file with the name .nomedia.
2. Prefix folder with a dot:
You can rename the folder itself with a dot. Example: .images.
So last night i thought i had my app working, however, this morning the gremlins have invaded and have now made a function of my app not work correctly.
Basically, a button allows the user to take a photo, and have that photo displayed in an Imageview, then attach the image to an email.. It lets me take the photo, and it is still present as an attachment, but the preview in the image view is completely empty.
Can anybody see what is going on?
Hoon_Image = (ImageView) findViewById(R.id.CapturedImage);
button_take_photo = (Button)findViewById(R.id.btn_take_photo);
button_take_photo.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
try {
f = createImageFile();
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
public File getAlbumDir()
{
File storageDir = new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES
),
"BAC/"
);
// Create directories if needed
if (!storageDir.exists()) {
storageDir.mkdirs();
}
return storageDir;
}
private File createImageFile() throws IOException {
// Create an image file name
String imageFileName =getAlbumDir().toString() +"/image.jpg";
File image = new File(imageFileName);
return image;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if(requestCode == CAMERA_REQUEST ){
Bitmap photo = BitmapFactory.decodeFile(f.getAbsolutePath());
Hoon_Image.setImageBitmap(photo);
}
}
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
//OI FILE Manager
filemanagerstring = selectedImageUri.getPath();
//MEDIA GALLERY
selectedImagePath = getPath(selectedImageUri);
//DEBUG PURPOSE - you can delete this if you want
if(selectedImagePath!=null)
System.out.println(selectedImagePath);
else System.out.println("selectedImagePath is null");
if(filemanagerstring!=null)
System.out.println(filemanagerstring);
else System.out.println("filemanagerstring is null");
//NOW WE HAVE OUR WANTED STRING
if(selectedImagePath!=null)
System.out.println("selectedImagePath is the right one for you!");
else
System.out.println("filemanagerstring is the right one for you!");
}
Bitmap photo = BitmapFactory.decodeFile(selectedImagePath);
Hoon_Image.setImageBitmap(photo);
Photo_Selected = 1;
}
}
What I've done for the image to be shown in the ImageView in Android is to use a method decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight) that decodes the File object with a required width and height. Below is a sample code.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_OK) {
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "image.jpg");
bitmap = decodeSampledBitmapFromFile(file.getAbsolutePath(),
600, 450);
imageView.setImageBitmap(bitmap);
}
}
public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth,
int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
// Query bitmap without allocating memory
options.inJustDecodeBounds = true;
// decode file from path
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
// decode according to configuration or according best match
options.inPreferredConfig = Bitmap.Config.RGB_565;
int inSampleSize = 1;
if (height > reqHeight) {
inSampleSize = Math.round((float) height / (float) reqHeight);
}
int expectedWidth = width / inSampleSize;
if (expectedWidth > reqWidth) {
// if(Math.round((float)width / (float)reqWidth) > inSampleSize) //
// If bigger SampSize..
inSampleSize = Math.round((float) width / (float) reqWidth);
}
// if value is greater than 1,sub sample the original image
options.inSampleSize = inSampleSize;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
So i found to what i was doing wrong - derp moment coming right up.
this section of code:
if (resultCode == RESULT_OK) {
if(requestCode == CAMERA_REQUEST ){
it was just looking of ok result (which happened both for selecting a photo and taking a photo successfully) rather than first looking for the RequestCode.
rearranging the code to this worked:
if(requestCode == CAMERA_REQUEST ) {
if (resultCode == RESULT_OK){
Bitmap photo = BitmapFactory.decodeFile(f.getAbsolutePath());
Hoon_Image.setImageBitmap(photo);
I'm trying to set image taken from the camera into an ImageView. I launch the camera intent and then I got a NullPointerException in OnActivityResult an I don't understand the error.
Here, I launche the camera intent and I store the image in the gallery of the phone :
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
imageUri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAMERA_REQUEST);
Now, the image token by the camera is saved in the gallery of the phone (high quality).
In onActivityResult, I want to put the image into a ImageView. This is my code :
else if (requestCode == CAMERA_REQUEST)
{
if (resultCode == RESULT_OK)
{
imageUri = data.getData();
try
{
Bitmap bitmap = Media.getBitmap(getContentResolver(), imageUri); //NullPointerException
myImageView.setImageBitmap(bitmap);
}
catch (IOException e)
{
e.printStackTrace();
}
I have a NullPointerException, why ? How can I resolve it please ?
This make your result save in mediaStore, so data.getData(); will return NULL:
pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
Remove it and you will get data for show on ImageView. However, if you get image from data directly, it's in bad quality
Your code is incomplete and you haven't added the logcat errors!
so in this condition it very difficult to guide you! but what you want to acheive is not that much difficult.Try this:
public class LaunchCamera extends Activity {
ImageView imVCature_pic;
Button btnCapture;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch_camera);
initializeControls();
}
private void initializeControls() {
imVCature_pic=(ImageView)findViewById(R.id.imVCature_pic);
btnCapture=(Button)findViewById(R.id.btnCapture);
btnCapture.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
/* create an instance of intent
* pass action android.media.action.IMAGE_CAPTURE
* as argument to launch camera
*/
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
/*create instance of File with name img.jpg*/
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "img.jpg");
/*put uri as extra in intent object*/
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
/*start activity for result pass intent as argument and request code */
startActivityForResult(intent, 1);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//if request code is same we pass as argument in startActivityForResult
if(requestCode==1){
//create instance of File with same name we created before to get image from storage
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "img.jpg");
//get bitmap from path with size of
imVCature_pic.setImageBitmap(decodeSampledBitmapFromFile(file.getAbsolutePath(), 600, 450));
}
}
public static Bitmap decodeSampledBitmapFromFile(String path,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
//Query bitmap without allocating memory
options.inJustDecodeBounds = true;
//decode file from path
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
//decode according to configuration or according best match
options.inPreferredConfig = Bitmap.Config.RGB_565;
int inSampleSize = 1;
if (height > reqHeight) {
inSampleSize = Math.round((float)height / (float)reqHeight);
}
int expectedWidth = width / inSampleSize;
if (expectedWidth > reqWidth) {
//if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize..
inSampleSize = Math.round((float)width / (float)reqWidth);
}
//if value is greater than 1,sub sample the original image
options.inSampleSize = inSampleSize;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
}
complete code snippet is described well here.