Ich suche auf 'developer.android.com', um meine Bitmap-Datei zu verkleinern und ich habe eine Sache gefunden, die ich nicht verstehe. also schätze ich es, dass du mir ein wenig hilfst.android - calculateInSampleSize, warum behandelt Math.round die Höhe (Höhe/reqHeight), wenn Breite> Höhe?
Hier ist ein snippet von developer.android.com
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height/(float)reqHeight);
} else {
inSampleSize = Math.round((float)width/(float)reqWidth);
}
}
return inSampleSize;
}
in if-Anweisung, wenn "if (Breite> Höhe)" warum sie berechnen "(float) Größe/(float) reqHeight"?
zum Beispiel, Breite = 600, Höhe = 800, reqWidth = 100, reqHeight = 100.
In dieser Situation wäre inSampleSize 6 und die berechneten Dimensionen sind Breite = 100, Höhe = 133. Höhe ist immer noch über reqHeight ..
also, kann mir bitte jemand erklären? Entschuldigung für komplizierte Erklärung, aber Ich hoffe, jemand gibt mir eine Idee. :)
Thx! also scheint ihre Logik falsch zu sein ..! – user1874389