enzostar Posted October 7, 2011 Share Posted October 7, 2011 Bonjour, je souhaiterais afficher une image pour laquelle je souhaiterais définir les dimensions, le tout en java. Actuellement mon image s'affiche, mais elle est beaucoup trop grande. Merci pour votre aide. Link to comment Share on other sites More sharing options...
chpil Posted October 7, 2011 Share Posted October 7, 2011 Tu utilises quoi pour afficher ton image ? Une ImageView ? Si oui, regarde du côté des méthodes setMaxWidth/setMaxHeight/setScaleType, ça semble pouvoir répondre à ton besoin Link to comment Share on other sites More sharing options...
enzostar Posted October 7, 2011 Author Share Posted October 7, 2011 c'est exactement ce que j'ai fait, mais mon nimage n'apparait pas si je rajoute cela ImageView img = new ImageView(this); img.setImageResource(R.drawable.imagepersonne); img.setAdjustViewBounds(true); img.setMaxHeight(100); img.setMaxWidth(100); img.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); Link to comment Share on other sites More sharing options...
Potoman Posted October 8, 2011 Share Posted October 8, 2011 Moi perso, j'ai une Bitmap que j'utilise pour mettre dans une ImageView, c'est bidon et j'utilise ça pour la redimenssionné : public void resizeImage() { if (image != null) { int width = image.getWidth(); int height = image.getHeight(); float scaleWidth = ((float) (getWindowManager().getDefaultDisplay().getWidth() / 2)) / width; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleWidth); image = Bitmap.createBitmap(image, 0, 0, width, height, matrix, true); //BitmapDrawable bmp = new BitmapDrawable(resizedBitmap); } } Voilà :) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.