【问题标题】:How to use Fresco to read any package's gif image in the assets directory如何使用 Fresco 读取 assets 目录下任意包的 gif 图片
【发布时间】:2015-09-15 15:35:39
【问题描述】:

我知道如何读取本地包资产目录中的 gif 图像。但现在我需要在其他包资产中读取其他 gif 图像。例如主APP com.aaa.app 读取资产中的com.bbb.app gif。我知道使用

try {
    context = this.createPackageContext("com.bbb.app",
         Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
}

AssetManager am = context.getResources().getAssets();  
try {  
    InputStream is = am.open(fileName);  
    image = BitmapFactory.decodeStream(is);  
    is.close();  
} catch (IOException e) {  
    e.printStackTrace();  
} 

要阅读 jpg/png,但我想阅读 gif 使用 Fresco lib。有人知道怎么做吗?

【问题讨论】:

    标签: android gif fresco


    【解决方案1】:

    一旦你有了 gif 的 uri,就用 fresco 加载它

    SimpleDraweeView simpleDraweeView = (SimpleDraweeView) findViewById(R.id.imageview);
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithResourceId(R.raw.sample_gif).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
    .setUri(imageRequest.getSourceUri())
    .setAutoPlayAnimations(true)
    .build();
    simpleDraweeView.setController(controller);
    

    【讨论】:

      【解决方案2】:

      别忘了将此添加到您的build.gradle:

      compile 'com.facebook.fresco:animated-gif:0.12.0'
      

      【讨论】:

        【解决方案3】:

        目前,Fresco 支持以下功能:

        Uri uri = Uri.parse("asset:///image.png");
        

        翻译成:

        AssetManager.openFd("image.png");
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-06-30
          • 1970-01-01
          • 2021-09-25
          • 1970-01-01
          • 2023-03-28
          • 2010-09-21
          相关资源
          最近更新 更多