How to use Fresco to read any package's gif image in the assets directory

我们两清 提交于 2019-12-05 06:43:34

问题


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?


回答1:


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



回答2:


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

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



回答3:


At the moment, Fresco supports the following:

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

Which gets translated into:

AssetManager.openFd("image.png");


来源:https://stackoverflow.com/questions/31111163/how-to-use-fresco-to-read-any-packages-gif-image-in-the-assets-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!