I developed an activity where load a gif. In my Galaxy S III mini the gif load normaly, but in moto x... =(
我开发了一个加载gif的活动。在我的Galaxy S III mini中,gif负载正常,但在moto x ... =(
The error occurs in line: movie.draw(canvas, 0, 0);
错误发生在行:movie.draw(canvas,0,0);
My class Gif extends from View
我的班级Gif从View扩展
The code is:
代码是:
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();
}
Layout element:
<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"/>
The error:
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 个解决方案
#1
0
Solved.
My InputStream in some smartphones was null, so I get the byte array of my gifs and decode to Movie.
我的一些智能手机中的InputStream为null,所以我得到了我的GIF字节数组并解码为Movie。
Code:
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();
}
But now I avoid the error, but in some android the gif doesn't show.
但是现在我避免了错误,但在某些android中gif没有显示。
Basically I did not solve, only avoid throw. In my undertand this is a problem of memory or the extraction of image from sdcard.
基本上我没有解决,只能避免抛出。在我的工作中,这是一个记忆问题或从SD卡中提取图像。
#1
0
Solved.
My InputStream in some smartphones was null, so I get the byte array of my gifs and decode to Movie.
我的一些智能手机中的InputStream为null,所以我得到了我的GIF字节数组并解码为Movie。
Code:
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();
}
But now I avoid the error, but in some android the gif doesn't show.
但是现在我避免了错误,但在某些android中gif没有显示。
Basically I did not solve, only avoid throw. In my undertand this is a problem of memory or the extraction of image from sdcard.
基本上我没有解决,只能避免抛出。在我的工作中,这是一个记忆问题或从SD卡中提取图像。