How to use Fresco to read any package's gif im

2019-04-02 10:43发布

I know how to read the gif image in local package assets directory. But now I need read other gif image in other package assets. for example the main APP com.aaa.app to read the com.bbb.app gif in assets. I know use

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();  
} 

to read jpg/png, but I want to read gif use Fresco lib. Anyone know how to do it?

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-02 11:28

once you have the uri of the gif, do this to load it with 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);
查看更多
走好不送
3楼-- · 2019-04-02 11:37

At the moment, Fresco supports the following:

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

Which gets translated into:

AssetManager.openFd("image.png");
查看更多
贼婆χ
4楼-- · 2019-04-02 11:42

Don't forget to add this to your build.gradle:

compile 'com.facebook.fresco:animated-gif:0.12.0'
查看更多
登录 后发表回答