Stretch / scale specific region of view / bitmap

I am trying to apply ScaleAnimation to a View , but I have a somewhat unconventional requirement: I would like to scale only a very specific view area.

Using the existing ScaleAnimation class, I can easily evenly scale the view. I can also set a pivot point at which to scale the view. The following is an example of this:

smiley scaled from bottom

It's simple. But I want to achieve the following, which is associated with scaling only a certain area of ​​the view (or in this case a small horizontal rectangle in the middle of the emoticon):

smiley with specific region scaled

I dug up the source code for ScaleAnimation , and the following function is apparently responsible for scaling:

 protected void applyTransformation(float interpolatedTime, Transformation t) { float sx = 1.0f; float sy = 1.0f; if (mFromX != 1.0f || mToX != 1.0f) { sx = mFromX + ((mToX - mFromX) * interpolatedTime); } if (mFromY != 1.0f || mToY != 1.0f) { sy = mFromY + ((mToY - mFromY) * interpolatedTime); } if (mPivotX == 0 && mPivotY == 0) { t.getMatrix().setScale(sx, sy); } else { t.getMatrix().setScale(sx, sy, mPivotX, mPivotY); } } 

Since this function simply applies the scaling operation to the matrix, I thought there was some kind of matrix operation that I could use to write a custom scaling animation, but I don't have the know-how in linear algebra. The solution to this can be much simpler, since others seem to have encountered this problem, but I could not find any solutions. Thanks in advance.

+4
source share
1 answer

The matrix converts the entire bitmap. You cannot scale regions with a single matrix.

+1
source

All Articles