I managed to get it to work with the following approach. I think you could do it without AsyncTask, but it seems that in best practice, you should do image processing in a thread other than the UI (please feel free to fix it), I'm brand new in this).
An improvement that could be made with this would be more detailed handling of scaling. inSampleSize is a great tool, but it will only scale with degrees 2. Another improvement would be to only read meta / EXIF data in bmOriginal , since the only use of this variable is to get the height and width.
ImageView XML is pretty standard. android: layout_width / height is set to fill_parent .
From java activity file -
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_image); new ImageRotator().execute(MainActivity.image_path); } private class ImageRotator extends AsyncTask<String, Void, Bitmap>{ protected Bitmap doInBackground(String... image_path){ BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inSampleSize = 4; Bitmap bmOriginal = BitmapFactory.decodeFile(image_path[0], bitmapOptions); Matrix matrix = new Matrix(); matrix.postRotate(90); bmOriginal = Bitmap.createBitmap(bmOriginal, 0, 0, bmOriginal.getWidth(), bmOriginal.getHeight(), matrix, true); return bmOriginal; } protected void onPostExecute(Bitmap result) { myImageView = (ImageView) findViewById(R.id.myImageView); myImageView.setImageBitmap(result); } }
The scaling process was found here and there is a great explanation of the AsyncTask features.
Thanks to everyone who answered and again - please feel free to let me know if this is far from the base or even if there is only the best way to do this.
source share