在 java/android 中将字节数组转换为 gif
convert byte array into gif in java/android
在我的 android 应用程序中,我从服务器接收字节数组,必须将它们转换为 .gif 图像,然后将其放在视图中。
我已经知道如何使用 BitmapFactory 将它们转换为静止图像,但图像总是静止不动。
我使用 gif-drawable 作为 .gif 图像的容器视图。我已经用本地动画 gif 对其进行了测试,效果很好。
如何将字节数组放入 gif-drawable 视图中?
在布局中我有这个:
<pl.droidsonroids.gif.GifImageView
android:id="@+id/imgExerciseImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="exercise image" />
这是一个类似于 ImageView 的视图,可以显示 gif 动画
我想在其中显示从我的 firebase 服务器收到的图像。这是代码:
imageRef.getBytes(DatabaseConstants.ONE_MEGABYTE * 3).addOnSuccessListener(new OnSuccessListener<byte[]>() {
@Override
public void onSuccess(byte[] bytes) {
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
imgExerciseImage.setImageBitmap(bitmap);
progressDialog.dismiss();
}
}
字节[]是gif动画。但是为了把它放在我的视图中,我必须使用 byte[] 来形成图像。在此示例中,我使用 BitmapFactory 创建位图。我如何创建 gif 而不是位图?
gif-drawable 似乎带有一个 GifDrawable 对象,该对象可以在其构造函数中接收字节数组以创建动画 gif,然后将其放置在 GifImageView 中
try {
GifDrawable gif = new GifDrawable(bytes);
imgExerciseImage.setImageDrawable(gif);
} catch (IOException e) {
e.printStackTrace();
}
在我的 android 应用程序中,我从服务器接收字节数组,必须将它们转换为 .gif 图像,然后将其放在视图中。 我已经知道如何使用 BitmapFactory 将它们转换为静止图像,但图像总是静止不动。 我使用 gif-drawable 作为 .gif 图像的容器视图。我已经用本地动画 gif 对其进行了测试,效果很好。 如何将字节数组放入 gif-drawable 视图中?
在布局中我有这个:
<pl.droidsonroids.gif.GifImageView
android:id="@+id/imgExerciseImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="exercise image" />
这是一个类似于 ImageView 的视图,可以显示 gif 动画
我想在其中显示从我的 firebase 服务器收到的图像。这是代码:
imageRef.getBytes(DatabaseConstants.ONE_MEGABYTE * 3).addOnSuccessListener(new OnSuccessListener<byte[]>() {
@Override
public void onSuccess(byte[] bytes) {
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
imgExerciseImage.setImageBitmap(bitmap);
progressDialog.dismiss();
}
}
字节[]是gif动画。但是为了把它放在我的视图中,我必须使用 byte[] 来形成图像。在此示例中,我使用 BitmapFactory 创建位图。我如何创建 gif 而不是位图?
gif-drawable 似乎带有一个 GifDrawable 对象,该对象可以在其构造函数中接收字节数组以创建动画 gif,然后将其放置在 GifImageView 中
try {
GifDrawable gif = new GifDrawable(bytes);
imgExerciseImage.setImageDrawable(gif);
} catch (IOException e) {
e.printStackTrace();
}