在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:WayGif开源软件地址:https://gitee.com/way/WayGif开源软件介绍:##WayGif Android端通过jni解析显示gif图片,更高效,更速度。原项目来自Github: android-gif-drawable ##简单使用 ###在layout布局XML文件中:跟使用普通的 <com.way.gif.GifImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/src_anim" android:background="@drawable/bg_anim" /> 如果
<com.way.gif.GifTextView android:layout_width="match_parent" android:layout_height="match_parent" android:drawableTop="@drawable/left_anim" android:drawableStart="@drawable/left_anim" android:background="@drawable/bg_anim" /> ###在Java代码中:
//asset file GifDrawable gifFromAssets = new GifDrawable( getAssets(), "anim.gif" ); //resource (drawable or raw) GifDrawable gifFromResource = new GifDrawable( getResources(), R.drawable.anim ); //byte array byte[] rawGifBytes = ... GifDrawable gifFromBytes = new GifDrawable( rawGifBytes ); //FileDescriptor FileDescriptor fd = new RandomAccessFile( "/path/anim.gif", "r" ).getFD(); GifDrawable gifFromFd = new GifDrawable( fd ); //file path GifDrawable gifFromPath = new GifDrawable( "/path/anim.gif" ); //file File gifFile = new File(getFilesDir(),"anim.gif"); GifDrawable gifFromFile = new GifDrawable(gifFile); //AssetFileDescriptor AssetFileDescriptor afd = getAssets().openFd( "anim.gif" ); GifDrawable gifFromAfd = new GifDrawable( afd ); //InputStream (it must support marking) InputStream sourceIs = ... BufferedInputStream bis = new BufferedInputStream( sourceIs, GIF_LENGTH ); GifDrawable gifFromStream = new GifDrawable( bis ); //direct ByteBuffer ByteBuffer rawGifBytes = ... GifDrawable gifFromBytes = new GifDrawable( rawGifBytes );
Note that all input sources need to have ability to rewind to the begining. It is required to correctly play animated GIFs(where animation is repeatable) since subsequent frames are decoded on demand from source. ####Animation control
#####Using MediaPlayerControlStandard controls for a MediaPlayer (like in VideoView) can be used to control GIF animation and show its current progress. Just set @Override protected void onCreate ( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); GifImageButton gib = new GifImageButton( this ); setContentView( gib ); gib.setImageResource( R.drawable.sample ); final MediaController mc = new MediaController( this ); mc.setMediaPlayer( ( GifDrawable ) gib.getDrawable() ); mc.setAnchorView( gib ); gib.setOnClickListener( new OnClickListener() { @Override public void onClick ( View v ) { mc.show(); } } ); } ####Retrieving GIF metadata
####Advanced 测试截图 |
请发表评论