Mise à l'échelle du bitmap Android

/**
 * Le format d'image prend la valeur maximale pour mettre l'image à l'échelle.
 *
 * Image chargée en bitmap @param
 * @param widthSize La largeur de l'image après mise à l'échelle, généralement la largeur de l'écran.
 * @param heightSize La hauteur de l'image après mise à l'échelle, généralement la hauteur de l'écran.
 */
public static Bitmap ScaleImgMax(Bitmap bitmap, int widthSize, int heightSize) {
    int bmpW = bitmap.getWidth();
    int bmpH = bitmap.getHeight();
    float scaleW = ((float) widthSize) / bmpW ;
    float scaleH = ((float) heightSize) / bmpH ;
    // Prendre le rapport maximum de largeur et de hauteur pour zoomer l'image
    float max = Math.max(scaleW, scaleH);
    Matrice matrice = new Matrice();
    matrice.postScale(max, max);
    return Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, matrice, true);
}
/**
 * La largeur et la hauteur sont étirées séparément
 *
 * Image chargée en bitmap @param
 * @param widthSize La largeur de l'image après mise à l'échelle, généralement la largeur de l'écran.
 * @param heightSize La hauteur de l'image après mise à l'échelle, généralement la hauteur de l'écran.
 */
public static Bitmap ScaleImgMax(Bitmap bitmap, int widthSize, int heightSize) {
    int bmpW = bitmap.getWidth();
    int bmpH = bitmap.getHeight();
    float scaleW = ((float) widthSize) / bmpW ;
    float scaleH = ((float) heightSize) / bmpH ;

    Matrice matrice = new Matrice();
    matrix.postScale(scaleW, scaleH);
    return Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, matrice, true);
}

おすすめ

転載: blog.csdn.net/zhao8856234/article/details/127700693