纹理格式无效!加载gif时返回错误

时间:2015-05-10 15:46:37

标签: android textures buffer gif

我开发了一个加载gif的活动。在我的Galaxy S III mini中,gif负载正常,但在moto x ... =(

错误发生在:movie.draw(canvas,0,0);

我的班级Gif从View

扩展

代码是:

protected void onDraw(Canvas canvas) {

    float escala = getEscala(canvas);
    setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int)(movie.height()*escala)));
    canvas.scale(escala,escala);
    canvas.drawColor(Color.TRANSPARENT);

    super.onDraw(canvas);
    long horaAtual = android.os.SystemClock.uptimeMillis();
    if (movieStart == 0) {
        movieStart = horaAtual;
    }
    if (movie != null) {
        int sequencia = (int) ((horaAtual - movieStart) % movie.duration());
        movie.setTime(sequencia);
        movie.draw(canvas, 0, 0);
        this.invalidate();
    }
}



private void initializeView() {
            if (inputStreamGif == null) {
                inputStreamGif = getContext().getResources().openRawResource(+R.drawable.carregando);
            }
            movie = Movie.decodeStream(inputStreamGif);
            movieStart = 0;
            this.invalidate();
        }

布局元素:

<view.elements.Gif
                    android:id="@+id/ivExercicio"
                    android:minHeight="900dp"
                    android:tag="carregando"
                    android:contentDescription="@string/contentDescription"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

错误:

E/Adreno-ES20﹕ <check_framebuffer_attachment:854>: Invalid texture format! Returning error!

E/Adreno-ES20﹕ <check_framebuffer_object_status:1237>: Framebuffer color attachment incomplete. Returning GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT!

E/Adreno-ES20﹕ <check_framebuffer_attachment:854>: Invalid texture format! Returning error!

E/Adreno-ES20﹕ <check_framebuffer_object_status:1237>: Framebuffer color attachment incomplete. Returning GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT!

1 个答案:

答案 0 :(得分:0)

解决。

我的一些智能手机中的InputStream为null,所以我得到了我的GIF字节数组并解码为Movie。

代码:

    private void initializeView() {
            if(array != null){
                movie = Movie.decodeByteArray(array, 0, array.length);
                movieStart = 0;
                this.invalidate();
            }

        }

protected void onDraw(Canvas canvas) {
        //BaseActivity.alertarThread(a, "Escala = " + escala + " - Movie L = " + movie.width() + " - Size W = " + w);

        setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));

        if(movie == null) return;

        setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (movie.height() * escala)));
        canvas.scale(escala, escala);
        //canvas.drawColor(Color.TRANSPARENT);

        super.onDraw(canvas);
        long horaAtual = android.os.SystemClock.uptimeMillis();
        if (movieStart == 0) {
            movieStart = horaAtual;
        }
        int duracao = movie.duration();
        if(duracao > 0)
        {
            sequencia = (int) ((horaAtual - movieStart) % movie.duration());
        }
        movie.setTime(sequencia);
        movie.draw(canvas, 0, 0);
        this.invalidate();
    }

但现在我避免了这个错误,但在某些android中,gif没有显示。

基本上我没有解决,只能避免抛出。在我的工作中,这是一个记忆问题或从SD卡中提取图像。