0

我有一个逐帧的AnimationDrawable缩放,我想在没有 Android 默认的模糊插值的情况下进行缩放。(这是像素​​艺术,最近邻看起来更好。)我可以设置一个标志吗?覆盖onDraw?有什么可以告诉 GPU 不要使用纹理过滤吗?

我是否需要放大动画中的每个单独的位图?这似乎是对 CPU 和纹理内存的浪费。

代码示例:

// Use a view background to display the animation.
View animatedView = new View(this);
animatedView.setBackgroundResource(R.anim.pixel_animation);
AnimationDrawable animation = (AnimationDrawable)animatedView.getBackground();
animation.start();

// Use LayoutParams to scale the animation 4x.
final int SCALE_FACTOR = 4;
int width = animation.getIntrinsicWidth() * SCALE_FACTOR;
int height = animation.getIntrinsicHeight() * SCALE_FACTOR;
container.addView(animatedView, width, height);
4

2 回答 2

1

这似乎可行,只要您可以假设 an 中的所有帧AnimationDrawable都是BitmapDrawables:

for(int i = 0; i < animation.getNumberOfFrames(); i++) {
    Drawable frame = animation.getFrame(i);
    if(frame instanceof BitmapDrawable) {
        BitmapDrawable frameBitmap = (BitmapDrawable)frame;
        frameBitmap.getPaint().setFilterBitmap(false);
    }
}
于 2014-05-20T23:59:28.180 回答
0

如果您知道正在渲染的纹理的纹理 ID,那么在它创建之后和渲染之前的任何时间,您应该能够执行以下操作:

glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

如果这是唯一要渲染的纹理,那么您可以从渲染线程的任何地方执行此操作,并且无需显式地获取它glBindTexture()

于 2014-05-20T03:29:18.580 回答