【问题标题】:Sharing GIF in Android在 Android 中分享 GIF
【发布时间】:2017-03-11 03:00:01
【问题描述】:

我正在开发一个 Android 应用程序,其中我必须实现与其他消息传递应用程序共享 GIF 的功能。

为此,我将其存储在一个临时文件中并通过意图传递文件的 url。我的 gif 存储为可绘制对象。因此,在检索它时,我使用了 FileOutputStream 和 Bitmap.Compress。由于这个而不是GIF,我得到了一个静止图像。

另外,我尝试在不压缩的情况下将位图转换为字节数组,但在这种情况下,我的图像没有显示出来

我分享 gif 的代码:

int drawableId = gridItemList.get(position);
Bitmap contentToShare = BitmapFactory.decodeResource(getResources(),   drawableId);                
try {
    File cachePath=new File(getApplicationContext().getFilesDir(),"content");
    cachePath.mkdirs();
    FileOutputStream stream=new FileOutputStream(cachePath+"/anim.gif");
    contentToShare.compress(Bitmap.CompressFormat.PNG, 100, stream);
    stream.close();
    File imagePath = new File(getApplicationContext().getFilesDir(), "content");
    File newFile = new File(imagePath,"anim.gif");
    Uri contentURI=FileProvider.getUriForFile(getApplicationContext(),getPackageName()+".fileprovider",newFile);
    if(contentURI!=null)    {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, contentURI);
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shareIntent.setType("image/gif");
        startActivity(shareIntent);
    }
}catch (Exception e)    {
    Log.e("Exception",e.toString());
}

PS : 共享 jpeg 和 png 效果很好。

【问题讨论】:

  • 发布您的代码...
  • 使用 Glide 库来展示你的 GIF
  • 我已经在使用 glide 从 drawable 加载 gif。但我无法分享 gif

标签: android gif


【解决方案1】:

使用 Glide 库显示您的 GIF

在你的 Gradle 中:

compile 'com.github.bumptech.glide:glide:3.7.0'

要编写的代码:

String gifUrl = "http://i.kinja-img.com/gawker-media/image/upload/s--B7tUiM5l--/gf2r69yorbdesguga10i.gif";

Glide  
    .with( context )
    .load( gifUrl )
    .into( imageViewGif );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2014-01-12
    • 2014-09-19
    • 1970-01-01
    • 2014-12-24
    相关资源
    最近更新 更多