Jump to content

Creer une image avec une taille personnalisée en java


enzostar

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...