List of usage examples for android.widget ImageView getMaxHeight
public int getMaxHeight()
From source file:com.afwsamples.testdpc.common.Util.java
public static void updateImageView(Context context, ImageView imageView, Uri uri) { try {//from ww w . ja va2 s. c o m InputStream inputStream = context.getContentResolver().openInputStream(uri); // Avoid decoding the entire image if the imageView holding this image is smaller. BitmapFactory.Options bounds = new BitmapFactory.Options(); bounds.inJustDecodeBounds = true; BitmapFactory.decodeStream(inputStream, null, bounds); int streamWidth = bounds.outWidth; int streamHeight = bounds.outHeight; int maxDesiredWidth = imageView.getMaxWidth(); int maxDesiredHeight = imageView.getMaxHeight(); int ratio = Math.max(streamWidth / maxDesiredWidth, streamHeight / maxDesiredHeight); if (ratio > 1) { bounds.inSampleSize = ratio; } bounds.inJustDecodeBounds = false; inputStream = context.getContentResolver().openInputStream(uri); imageView.setImageBitmap(BitmapFactory.decodeStream(inputStream, null, bounds)); } catch (FileNotFoundException e) { Toast.makeText(context, R.string.error_opening_image_file, Toast.LENGTH_SHORT); } }
From source file:xyz.jamescarroll.genipass.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*w w w . ja v a2s . c om*/ KeyManager.getInstance().setmControl(this); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); navigationView.getMenu().getItem(0).setChecked(true); ImageView iv = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.iv_nav_cover); Bitmap b = Bitmap.createScaledBitmap(((BitmapDrawable) getDrawable(R.drawable.genipass_header)).getBitmap(), iv.getMaxWidth(), iv.getMaxHeight(), false); iv.setImageBitmap(b); handleMemoryRequirements(); handleManagerFirstFragment(); }
From source file:es.upv.riromu.arbre.main.MainActivity.java
private void setPic() { // Get the dimensions of the View Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size);/* w ww . j a v a2s. co m*/ // Get the dimensions of the bitmap ImageView imv = (ImageView) findViewById(R.id.image_intro); int targetW = imv.getMaxWidth(); int targetH = imv.getMaxHeight(); BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; Bitmap bitmap = loadBitmap(image_uri.getPath()); int photoW = bitmap.getWidth(); int photoH = bitmap.getHeight(); imv.setImageBitmap(bitmap); galleryAddPic(); }