Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-计算没有矩阵的像素旋转?以及检查像素是否在视图中_Android_Math_Matrix_Rotation - Fatal编程技术网

Android-计算没有矩阵的像素旋转?以及检查像素是否在视图中

Android-计算没有矩阵的像素旋转?以及检查像素是否在视图中,android,math,matrix,rotation,Android,Math,Matrix,Rotation,我希望有人能帮我。我正在制作一个图像处理应用程序,我发现我需要一个更好的方法来加载大图像 我的计划是迭代图像的“假想”像素(覆盖基础图像宽度/高度的“for循环”,因此每次迭代代表一个像素),缩放/平移/旋转该像素相对于视图的位置,然后使用此信息确定视图中显示的像素,然后使用BitMapRegionCoder和BitmapFactory.Options的组合,仅加载输出实际需要的图像部分,而不是完整(即使缩放)图像 到目前为止,我似乎已经正确地讨论了图像的比例和平移,但我似乎不知道如何计算旋转。

我希望有人能帮我。我正在制作一个图像处理应用程序,我发现我需要一个更好的方法来加载大图像

我的计划是迭代图像的“假想”像素(覆盖基础图像宽度/高度的“for循环”,因此每次迭代代表一个像素),缩放/平移/旋转该像素相对于视图的位置,然后使用此信息确定视图中显示的像素,然后使用BitMapRegionCoder和BitmapFactory.Options的组合,仅加载输出实际需要的图像部分,而不是完整(即使缩放)图像

到目前为止,我似乎已经正确地讨论了图像的比例和平移,但我似乎不知道如何计算旋转。由于它不是真正的位图像素,我不能使用Matrix.rotate=(以下是视图onDraw中的图像转换,imgPosX和imgPosY保留图像的中心点:

m.setTranslate(-userImage.getWidth() / 2.0f, -userImage.getHeight() / 2.0f);
m.postScale(curScale, curScale);
m.postRotate(angle);
m.postTranslate(imgPosX, imgPosY);
mCanvas.drawBitmap(userImage.get(), m, paint);
以下是我目前试图确定屏幕上是否有图像像素的数学结果:

for(int j = 0;j < imageHeight;j++) {
    for(int i = 0;i < imageWidth;i++) {

        //image starts completely center in view, assume image is original size for simplicity
        //this is the original starting position for each pixel
        int x = Math.round(((float) viewSizeWidth / 2.0f) - ((float) newImageWidth / 2.0f) + i);
        int y = Math.round(((float) viewSizeHeight / 2.0f) - ((float) newImageHeight / 2.0f) + j);

        //first we scale the pixel here, easy operation
        x = Math.round(x * imageScale);
        y = Math.round(y * imageScale);

        //now we translate, we do this by determining how many pixels
        //our images x/y coordinates have differed from it's original
        //starting point, imgPosX and imgPosY in the view start in center
        //of view

        x = x + Math.round((imgPosX - ((float) viewSizeWidth / 2.0f)));
        y = y + Math.round((imgPosY - ((float) viewSizeHeight / 2.0f)));

        //TODO need rotation here

    }
}
for(int j=0;j
因此,假设我的数学直到旋转正确(可能不正确,但到目前为止它似乎工作正常),那么我将如何从该像素位置计算旋转?我尝试过其他类似的问题,如:

在不使用旋转的情况下,我希望屏幕上的像素会被表示出来(我制作了文本文件,以1和0的形式输出结果,这样我就可以直观地表示屏幕上的内容),但根据这些问题中的公式,信息并不是我所期望的。(场景:我旋转了一个图像,因此在视图中只有左上角可见。使用“来自”的信息旋转像素,我希望在输出文件的左上角看到一组三角形的1,但事实并非如此)

那么,在不使用Android矩阵的情况下,如何计算旋转后的像素位置呢?但仍然得到相同的结果

如果我把事情搞砸了,我道歉=(任何帮助都将被感激,这个项目已经进行了这么长时间,我想最终完成,哈哈

如果你需要更多的信息,我会尽可能多的提供谢谢你的时间


我意识到这个问题特别困难,所以我会尽快发布悬赏。

您不需要创建自己的矩阵,使用现有矩阵。

可以使用将位图坐标映射到屏幕坐标

float[] coords = {x, y};
m.mapPoints(coords);
float sx = coords[0];
float sy = coords[1];
如果要将屏幕映射到位图坐标,可以创建逆矩阵

Matrix inverse = new Matrix(m);
inverse.inverse();
inverse.mapPoints(...)

我认为你的整体方法会很慢,因为从Java在CU上进行像素操作会有很大的开销。正常绘制位图时,像素操作会在GPU上进行。

我明天会尽快对此进行尝试。^谢谢你的时间。我知道这会很慢,但应用程序只是为了一个理想的目的仅输出gle pass,我只需要一次就可以了,所以在速度和内存方面,我需要达到最佳内存使用率=)