我有这段代码.我不理解matrix.prescale()和传递矩阵的createBitmap.这是什么意思?有没有模拟网站来理解矩阵计算?你能给我一些关于图形数学的网站吗?对不起,我不擅长数学.:)
public Bitmap createReflectedImages(final Bitmap originalImage) {
final int width = originalImage.getWidth();
final int height = originalImage.getHeight();
final Matrix matrix = new Matrix();
matrix.preScale(1, -1);
final Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, (int) (height * imageReflectionRatio),
width, (int) (height - height * imageReflectionRatio), matrix, false);
final Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (int) (height + height * imageReflectionRatio + 400),
Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(originalImage, 0, 0, null);
final Paint deafaultPaint = new Paint();
deafaultPaint.setColor(color.transparent);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
final Paint paint = new Paint();
final LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
return bitmapWithReflection;
}
Run Code Online (Sandbox Code Playgroud)
Sim*_*mon 88
不要想太难,至少不要在早期阶段.
只需将矩阵视为一组数字.在这种情况下,Android Matrix有3行3个数字.每个数字告诉Android图形功能如何缩放(更大/更小),平移(移动),旋转(转动)或倾斜(在2D平面中扭曲)矩阵应用于的"事物".
矩阵看起来像这样(参见这里的文档).
{Scale X, Skew X, Transform X
Skew Y, Scale Y, Transform Y
Perspective 0, Perspective 1, Perspective 2}
Run Code Online (Sandbox Code Playgroud)
好消息是你不需要知道在Android中使用矩阵的任何矩阵数学,实际上几乎没有数学.这就是preScale()这样的方法.要理解背后的数学并不是那么难,对于大多数事情你只需要添加,乘法和SOHCAHTOA.
当您阅读Matrix文档时,您将看到旋转,翻译等方法,前缀为"set","post"或"pre".
想象一下,您创建了一个新矩阵.然后使用setRotate()设置矩阵以进行旋转.然后使用preTranslate()进行翻译.因为你使用'pre',所以翻译发生在旋转之前.如果你使用'post',旋转将首先发生.'set'清除矩阵中的任何内容并重新开始.
为了回答您的具体问题,新的Matrix()创建了'单位矩阵'
{1, 0, 0
0, 1, 0
0, 0, 1}
Run Code Online (Sandbox Code Playgroud)
它缩放1(因此大小相同)并且没有平移,旋转或倾斜.因此,应用单位矩阵将不起作用.下一个方法是preScale(),它应用于此单位矩阵,在您显示的情况下,会产生一个可以缩放的矩阵,并且不会执行任何其他操作,因此也可以使用setScale()或postScale()来完成.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
11860 次 |
| 最近记录: |