As suggested by gnuanu, `setImageURI()` is not better to use as reading and decoding on the UI thread, which can cause a latency hiccup.
Better to use the following:-
`setImageDrawable(android.graphics.drawable.Drawable) or setImageBitmap(android.graphics.Bitmap) and BitmapFactory instead.`
Still these methods didn't solve my problem. As I was taking Picture with Camera and onClick of it sending to Next Activity which may cause latency hiccups.
So better to pass to another activity after some peroid of time . . just a sec is totally convient to get through it.
Snippet which solve my issue:-
final Intent picIntent = new Intent(CameraActivity.this,PicSaveActivity.class);
picIntent.putExtra("URI", pathUri.toString());
Handler handler = new Handler()
{
public void handleMessage(Message msg) {
startActivityForResult(picIntent, PICTAKEN);
};
};
Message msg = handler.obtainMessage();
handler.sendMessageDelayed(msg, 1000);
In Next Activity, catch the URI and rotate the Image as it would be in landscape mode.
if(absPathUri!=null)
{
Bitmap myImg = BitmapFactory.decodeFile(absPathUri.getPath());
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(),
matrix, true);
imgView.setImageBitmap(rotated);
}
As suggested by gnuanu, `setImageURI()` is not better to use as reading and decoding on the UI thread, which can cause a latency hiccup.
Better to use the following:-
`setImageDrawable(android.graphics.drawable.Drawable) or setImageBitmap(android.graphics.Bitmap) and BitmapFactory instead.`
Still these methods didn't solve my problem. As I was taking Picture with Camera and onClick of it sending to Next Activity which may cause latency hiccups.
So better to pass to another activity after some peroid of time . . just a sec is totally convient to get through it.
Snippet which solve my issue:-
final Intent picIntent = new Intent(CameraActivity.this,PicSaveActivity.class);
picIntent.putExtra("URI", pathUri.toString());
Handler handler = new Handler()
{
public void handleMessage(Message msg) {
startActivityForResult(picIntent, PICTAKEN);
};
};
Message msg = handler.obtainMessage();
handler.sendMessageDelayed(msg, 1000);
In Next Activity, catch the URI and rotate the Image as it would be in landscape mode.
if(absPathUri!=null)
{
Bitmap myImg = BitmapFactory.decodeFile(absPathUri.getPath());
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(),
matrix, true);
imgView.setImageBitmap(rotated);
}