gpt4 book ai didi

android - 在带有 Movie 的 ImageView 中显示 gif

转载 作者:搜寻专家 更新时间:2023-11-01 09:37:19 26 4
gpt4 key购买 nike

我在 ImageView with Movie 中显示 gif 时遇到问题。

代码如下:

public class CustomImageView extends ImageView {
private Context mContext;
private int movieWidth, movieHeight;
private long movieDuration;
private long movieStart;
private Movie movie;
private boolean isGif;
private File gifFile;

@Override
protected void onMeasure(int widthMeasureSpec,
int heightMeasureSpec) {
setMeasuredDimension(movieWidth, movieHeight);
}

@Override
protected void onDraw(Canvas canvas) {
if(isGif){
long now = android.os.SystemClock.uptimeMillis();
if (movieStart == 0) { // first time
movieStart = now;
}
if (movie != null) {
int dur = movie.duration();
if (dur == 0) {
dur = 1000;
}
int relTime = (int)((now - movieStart) % dur);
movie.setTime(relTime);
movie.draw(canvas, 0, 0);
invalidate();
}
}
//super.onDraw(canvas);
}

public CustomImageView(Context context) {
super(context);
mContext = context;
}

public CustomImageView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
}

public CustomImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
}

public CustomImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mContext = context;
}

public void setIsGif(boolean gif, File file){
if(gif){
isGif = true;
gifFile = file;
BufferedInputStream uriInputStream = null;
try {
uriInputStream = new BufferedInputStream(mContext.getContentResolver().openInputStream(Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.gif")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
movie = Movie.decodeStream(uriInputStream);
movieWidth = movie.width();
movieHeight = movie.height();
movieDuration = movie.duration();
}else{
isGif = false;
}
}

但它崩溃了,没有捕获到任何异常。

android logcat 如下:

02-06 16:06:52.056 23795-23795/com.weiwa.ljl.testimageview E/System: stat file error, path is /data/app/com.weiwa.ljl.testimageview-2/lib/arm64, exception is android.system.ErrnoException: stat failed: ENOENT (No such file or directory)
02-06 16:06:52.564 23795-23833/com.weiwa.ljl.testimageview E/GED: Failed to get GED Log Buf, err(0)
02-06 16:06:52.605 23795-23795/com.weiwa.ljl.testimageview A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 23795 (l.testimageview)

我只是陷入了这个问题,不知道该怎么办。

最佳答案

试试 Glide。 https://github.com/bumptech/glide

这里是一个加载 Gif 的例子

  Glide.with(this)
.load(gifUrl)
.asGif()
.centerCrop()
.into(imageView);

关于android - 在带有 Movie 的 ImageView 中显示 gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42063436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com