1

我知道如何读取本地包资产目录中的 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。有人知道该怎么做吗?

4

3 回答 3

5

不要忘记将此添加到您的build.gradle

compile 'com.facebook.fresco:animated-gif:0.12.0'
于 2016-07-23T22:04:27.070 回答
5

一旦你有了 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);
于 2016-01-20T06:03:01.860 回答
2

目前,Fresco 支持以下内容:

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

被翻译成:

AssetManager.openFd("image.png");
于 2015-07-08T13:42:15.837 回答