问题
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