java - 我应该依靠 Android 来丢弃离屏绘制吗?

标签 java android math optimization

我有一个函数,它采用无缝位图并使用世界坐标在屏幕上向任何方向滚动它。有 4 个绘制(播放区域小于整个位图大小。所以最多,您将看到 4 个位图副本,只是绘制了不同的部分以保持无缝效果)。我想知道的是,我是否应该对矩形边界进行修改,以便它只将应该显示在屏幕上的部分显示出来?或者我应该让 Android 处理吗? 如果我自己做,我应该如何处理?就数学而言,世界坐标和翻译真的让我感到困惑。 :/

这是代码。

public void draw(Canvas canvas){

oCoords.x=(int) fX;
oCoords.y=(int) fY;

oTopLeft = gridContainingPoint(oCoords);
oTopRight.x = gridContainingPoint(oCoords).x + iWidth;
oTopRight.y = gridContainingPoint(oCoords).y;
oBottomLeft.x = gridContainingPoint(oCoords).x;
oBottomLeft.y = gridContainingPoint(oCoords).y + iHeight;
oBottomRight.x = gridContainingPoint(oCoords).x + iWidth;
oBottomRight.y = gridContainingPoint(oCoords).y + iHeight;

canvas.save();
canvas.translate(-fX, -fY);
oCloud.setBounds(oTopLeft.x, oTopLeft.y, oTopLeft.x + this.iImageWidth, oTopLeft.y + this.iImageHeight);
oCloud.draw(canvas);
oCloud.setBounds(oTopLeft.x + this.iImageWidth, oTopLeft.y, oTopLeft.x + (this.iImageWidth * 2), oTopLeft.y + this.iImageHeight);
oCloud.draw(canvas);
oCloud.setBounds(oTopLeft.x, oTopLeft.y + this.iImageHeight, oTopLeft.x + this.iImageWidth, oTopLeft.y + (this.iImageHeight * 2));
oCloud.draw(canvas);
oCloud.setBounds(oTopLeft.x + this.iImageWidth, oTopLeft.y + this.iImageHeight, oTopLeft.x + (this.iImageWidth * 2),oTopLeft.y + (this.iImageHeight * 2));
oCloud.draw(canvas);
canvas.restore();
}

最佳答案

我不确定我是否理解您发布的代码块的详细信息,但如果您询问 android clip 是否自动绘制到屏幕边界,答案是肯定的。因此,除非您想绘制比屏幕小的一部分,否则在绘制位图时不必设置边界。

关于java - 我应该依靠 Android 来丢弃离屏绘制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7464527/

相关文章:

java - JVM PermGen OOM 即使尚未达到 Max

java - 当用户离线时显示对话框并在用户在线时关闭它(使用广播接收器)

java - 如何在Expression类中使用math.pow()进行计算?

java - 更改 Intent 时禁用后退按钮

java - @ExceptionHandler 本地与全局

java - OSGi - 如何使用 FUSE ESB 添加 JVM 参数?

java - 使用数组计算时如何格式化输出?

java - RGB 到 HSV 转换

android - 如何确定 Android Gallery 中的运动方向?

python - 自动简化冗余算术关系