清楚地了解矩阵计算矩阵、清楚

2023-09-06 00:35:06 作者:漫步奋斗路

我有这个code段。我不明白的矩阵。preSCALE(),并通过矩阵createBitmap。 这是什么意思?是否有任何模拟的网站,了解矩阵计算?你能给我一些关于用于图形数学网站?我很抱歉,我不擅长数学。 :)

 公共位图createReflectedImages(最后的位图originalImage){
    最终诠释宽度= originalImage.getWidth();
    最终诠释身高= originalImage.getHeight();
    最终矩阵的矩阵=新的Matrix();
    矩阵preSCALE(1,-1)。
    最后的位图reflectionImage = Bitmap.createBitmap(originalImage,0,(INT)(高* imageReflectionRatio)
            宽度(INT)(高 - 高* imageReflectionRatio),矩阵,假);
    最后的位图bitmapWithReflection = Bitmap.createBitmap(宽度(INT)(高+高* imageReflectionRatio + 400),
            Config.ARGB_8888);
    最后的画布油画=新的Canvas(bitmapWithReflection);
    canvas.drawBitmap(originalImage,0,0,NULL);
    最后的油漆deafaultPaint =新的油漆();
    deafaultPaint.setColor(color.transparent);
    canvas.drawBitmap(reflectionImage,0,身高+ reflectionGap,NULL);
    最终的涂料粉刷=新的油漆();
    最后的LinearGradient着色器=新的LinearGradient(0,originalImage.getHeight(),0,
            bitmapWithReflection.getHeight()+ reflectionGap,0x70ffffff,至0x00FFFFFF,TileMode.CLAMP);
    paint.setShader(着色);
    paint.setXfermode(新PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0,高度,宽度,bitmapWithReflection.getHeight()+ reflectionGap,油漆);
    返回bitmapWithReflection;
}
 

解决方案

不要去想它太难了,至少不会在早期阶段。

试想一个矩阵数字数组中。在这种情况下,一个机器人矩阵具有3行的3个数字。每个号码告诉一个Android的图形功能做什么规模(大/小),翻译(移动),旋转(转)或歪斜(扭曲的2D平面)的矩阵应用于东西。

该矩阵如下所示(请参见文档这里)。

  {缩放X,倾斜X,X变换
斜Y,Y比例,转换ÿ
透视0,观点1,观点2}
 

好消息是,你不需要了解任何矩阵数学,确实几乎没有数学,用矩阵的Andr​​oid系统。这就是像preSCALE()方法,为你做。为了理解数学原理并不难,对于大多数的事情,你只需要加,乘, SOHCAHTOA

矩阵变换换了,数学上的挑战/

MatrixMethodsinDataMiningandPatternRecognition 其它文档类资源 CSDN下载

当您阅读Matrix文档,你会看到旋转的方法,翻译等与'设置','后'或'pre'prefixes。

想象一下,你创建一个新的矩阵。然后,使用setRotate()设置的矩阵做旋转。然后,使用preTranslate()做翻译。因为你用'pre',平移旋转之前发生。假如你使用的是'post',旋转将首先发生。 设置清除无论是在基体并再次开始。

要回答你的具体问题,新的Matrix()创建的矩阵

  {1,0,0
 0,1,0
 0,0,1}
 

其中1(因此同样大小)尺度并不做任何平移,旋转或倾斜。因此,申请单位矩阵会做什么。的下一个方法是preSCALE(),它被应用于该单位矩阵,在所述情况下,你所展示的,将导致在矩阵磅秤,并没有别的所以也可以使用setScale()或分频器()完成

希望这有助于。

I have this code snippet. I don't understand the matrix.prescale() and the createBitmap with the matrix passed. What does it mean? Is there any simulation website to understand matrix calculation? Could you give me some websites about mathematics used for graphics? I'm sorry I'm not good at mathematics. :)

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;
}

解决方案

Don't think about it too hard, at least not at the early stages.

Just think of a matrix as an array of numbers. In this case, an Android Matrix has 3 rows of 3 numbers. Each number tells an Android graphics function what to do to scale (bigger/smaller), translate (move), rotate (turn) or skew (distort in a 2D plane) the "thing" which the matrix is applied to.

The matrix looks like this (see the docs here).

{Scale X, Skew X, Transform X
Skew Y, Scale Y, Transform Y
Perspective 0, Perspective 1, Perspective 2}

The good news is that you don't need to know any matrix maths, indeed almost no maths, to use matrices in Android. That's what methods like preScale() do for you. To understand the maths behind is not that hard, for most things you only need add, multiply and SOHCAHTOA.

matrix-transform-for-the-mathematically-challenged/

When you read the Matrix documentation, you will see methods for rotate, translate etc with prefixes of 'set', 'post' or 'pre'.

Imagine that you create a new matrix. You then use setRotate() to setup the matrix to do a rotation. You then use preTranslate() to do a translation. Because you used 'pre', the translation happens before the rotation. Had you used 'post', the rotation would happen first. 'set' clears whatever is in the matrix and starts again.

To answer your specific question, new Matrix() creates the 'identity matrix'

{1, 0, 0
 0, 1, 0
 0, 0, 1}

which scales by 1 (therefore same size) and does no translation, rotation or skew. Therefore, applying the identity matrix will do nothing. The next method is preScale() which is applied to this identity matrix and in the case you've shown, results in a matrix that scales, and does nothing else so could also be done using setScale() or postScale().

Hope this helps.