In my app i am using this code to get Image from Gallery and Camera:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 10 && resultCode == Activity.RESULT_OK) {
Uri contentUri = data.getData();
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
imagePath = cursor.getString(column_index);
//Bitmap croppedImage = BitmapFactory.decodeFile(imagePath);
tempBitmap = BitmapFactory.decodeFile(imagePath);
if(!(tempBitmap == null))
{
// here i am changing display to the tempBitmap
photoBitmap = Bitmap.createScaledBitmap(tempBitmap, display.getWidth(), display.getHeight(), true);
//photoBitmap = Bitmap.createBitmap(tempBitmap, 0, 0, tempBitmap.getWidth(), tempBitmap.getHeight());
takePhotoFromGallery = true;// edited
}
else
Toast.makeText(getApplicationContext(), "Image is not valid", Toast.LENGTH_SHORT).show();
}
if(resultCode == RESULT_OK && requestCode==TAKE_PHOTO_CODE){
final File file = getTempFile(this);
try {
tempBitmap = Media.getBitmap(getContentResolver(), Uri.fromFile(file));
photoBitmap = Bitmap.createScaledBitmap(tempBitmap, display.getWidth(), display.getHeight(), true);
takePhotoFromCamera = true;
// do whatever you want with the bitmap (Resize, Rename, Add To Gallery, etc)
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Now, all works fine. But i got Image as Stratch.
I thaught it is because this line:
photoBitmap = Bitmap.createScaledBitmap(tempBitmap, display.getWidth(), display.getHeight(), true);
here i am stratching the image width,height with display’s width,height.
I want is the Image should be Dispaly as we can normaly show thew image in gallery. So how to make it possible ???
This is the image which i am snaping from the Camera:

And Now this is What i see in my Application:

Now Second image got little stratch. as because of that line code.
So what should i have to do to make is normal in its height and width ??
Thanks.
Thanks.
Use ImageView and set scale type of image view to Center-Inside.