Java Code Examples for android.graphics.Matrix.ScaleToFit
The following are Jave code examples for showing how to use
ScaleToFit of the
android.graphics.Matrix
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: PlusGram File: AndroidUtilities.java View Source Code | 5 votes |
public static void setRectToRect(Matrix matrix, RectF src, RectF dst, int rotation, Matrix.ScaleToFit align) { float tx, sx; float ty, sy; if (rotation == 90 || rotation == 270) { sx = dst.height() / src.width(); sy = dst.width() / src.height(); } else { sx = dst.width() / src.width(); sy = dst.height() / src.height(); } if (align != Matrix.ScaleToFit.FILL) { if (sx > sy) { sx = sy; } else { sy = sx; } } tx = -src.left * sx; ty = -src.top * sy; matrix.setTranslate(dst.left, dst.top); if (rotation == 90) { matrix.preRotate(90); matrix.preTranslate(0, -dst.width()); } else if (rotation == 180) { matrix.preRotate(180); matrix.preTranslate(-dst.width(), -dst.height()); } else if (rotation == 270) { matrix.preRotate(270); matrix.preTranslate(-dst.height(), 0); } matrix.preScale(sx, sy); matrix.preTranslate(tx, ty); }