BitmapUtilspublic abstract class BitmapUtils extends Object
Methods Summary |
---|
public static void | calculateCroppedSrcRect(int srcW, int srcH, int dstW, int dstH, int dstSliceH, int sampleSize, float vertSliceFrac, boolean absoluteFrac, float verticalMultiplier, android.graphics.Rect outRect)Calculate a center-crop rectangle for the given input and output
parameters. The output rectangle to use is written in the given outRect.
if (sampleSize < 1) {
sampleSize = 1;
}
final float regularScale;
final float wScale = (float) srcW / dstW;
final float hScale = (float) srcH / dstH;
if (hScale < wScale) {
regularScale = hScale / verticalMultiplier;
} else {
regularScale = wScale;
}
final float scale = Math.min(sampleSize, regularScale);
final int srcCroppedW = Math.round(dstW * scale);
final int srcCroppedH = Math.round(dstH * scale);
final int srcCroppedSliceH = Math.round(dstSliceH * scale);
final int srcHalfSliceH = Math.min(srcCroppedSliceH, srcH) / 2;
outRect.left = (srcW - srcCroppedW) / 2;
outRect.right = outRect.left + srcCroppedW;
final int centerV;
if (absoluteFrac) {
final int minCenterV = srcHalfSliceH;
final int maxCenterV = srcH - srcHalfSliceH;
centerV = Math.max(minCenterV, Math.min(maxCenterV, Math.round(srcH * vertSliceFrac)));
} else {
centerV = Math
.round(Math.abs(srcH - srcCroppedSliceH) * vertSliceFrac + srcHalfSliceH);
}
outRect.top = centerV - srcCroppedH / 2;
outRect.bottom = outRect.top + srcCroppedH;
| public static void | calculateCroppedSrcRect(int srcW, int srcH, int dstW, int dstH, android.graphics.Rect outRect)
calculateCroppedSrcRect(srcW, srcH, dstW, dstH, Integer.MAX_VALUE, outRect);
| public static void | calculateCroppedSrcRect(int srcW, int srcH, int dstW, int dstH, int sampleSize, android.graphics.Rect outRect)
if (sampleSize < 1) {
sampleSize = 1;
}
final float regularScale = Math.min(
(float) srcW / dstW,
(float) srcH / dstH);
final float scale = Math.min(sampleSize, regularScale);
final int srcCroppedW = Math.round(dstW * scale);
final int srcCroppedH = Math.round(dstH * scale);
outRect.left = (srcW - srcCroppedW) / 2;
outRect.right = outRect.left + srcCroppedW;
outRect.top = (srcH - srcCroppedH) / 2;
outRect.bottom = outRect.top + srcCroppedH;
|
|