malevich, Android显示位图库

分享于 

4分钟阅读

GitHub

  繁體 雙語
Android displaying bitmaps library
  • 源代码名称:malevich
  • 源代码网址:http://www.github.com/recoilme/malevich
  • malevich源代码文档
  • malevich源代码下载
  • Git URL:
    git://www.github.com/recoilme/malevich.git
    Git Clone代码到本地:
    git clone http://www.github.com/recoilme/malevich
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/recoilme/malevich
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    malevich

    Android显示位图库

    这个库仅仅是Google教程加载大型位图的包装:

    http://developer.android.com/intl/ru/training/displaying-bitmaps/load-bitmap.html

    的用法示例:

    https://github.com/recoilme/android-DisplayingBitmaps

    如何使用:

    
    //init
    
    
    Malevich malevich = new Malevich.Builder(this).build();
    
    
    
    //use
    
    
    malevich.load(mImageUrl).into(mImageView);
    
    
    
    
    

    ,这就是

    Advansed用法:

    内存和磁盘缓存参数

    
    ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams(this,"dir");
    
    
     cacheParams.memoryCacheEnabled = true;//Enable memory cache
    
    
     cacheParams.setMemCacheSizePercent(0.4f);//Percent of available memory for cache
    
    
     cacheParams.compressQuality = 90;//Compress quality
    
    
     cacheParams.compressFormat = Bitmap.CompressFormat.PNG;//Compress format
    
    
     cacheParams.diskCacheEnabled = true;//Use disk cache
    
    
     cacheParams.diskCacheSize = 10485760;//Disk cache size
    
    
    
    

    Malevich生成器

    
    malevich = new Malevich.Builder(this)
    
    
    . debug(true)//write log
    
    
    . maxSize(1024)//max size of image in px
    
    
    . LoadingImage(R.drawable.some)//preloader image or recource
    
    
    . CacheParams(casheParams)//custom cache
    
    
    . build();
    
    
    
    

    加载图像

    
    malevich.load(some).into(ImageView);
    
    
    
    

    你可以载入:

    • 位图
    • BitmapDrawable
    • 资源 ID
    • HttpUrl

    预编译工具加载后的转换映像或者自定义方法

    
    malevich.load(url).width(mItemHeight).height(mItemHeight).imageDecodedListener(new Malevich.ImageDecodedListener() {
    
    
     @Override
    
    
     public Bitmap onImageDecoded(String data, int reqWidth, int reqHeight, Bitmap bitmap) {
    
    
    
    //Get squared bitmap and transform it to circle
    
    
     return Malevich.Utils.getSquaredCircleBitmap(bitmap,reqWidth);
    
    
     }
    
    
     }).into(imageView);
    
    
    
    

    在滚动时暂停加载

    
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
    
    
     @Override
    
    
     public void onScrollStateChanged(AbsListView absListView, int scrollState) {
    
    
    //Pause fetcher to ensure smoother scrolling when flinging
    
    
     if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
    
    
    //Pause image loading on scroll to help with performance
    
    
     malevich.setPauseWork(true);
    
    
     } else {
    
    
     malevich.setPauseWork(false);
    
    
     }
    
    
     }
    
    
    
     @Override
    
    
     public void onScroll(AbsListView absListView, int firstVisibleItem,
    
    
     int visibleItemCount, int totalItemCount) {
    
    
     }
    
    
     });
    
    
    
    

    Canсel和暂停任务

    
     @Override
    
    
     public void onResume() {
    
    
     super.onResume();
    
    
     malevich.setExitTasksEarly(false);
    
    
     mAdapter.notifyDataSetChanged();
    
    
     }
    
    
    
     @Override
    
    
     public void onPause() {
    
    
     super.onPause();
    
    
     malevich.setPauseWork(false);
    
    
     malevich.setExitTasksEarly(true);
    
    
     malevich.flushCache();
    
    
     }
    
    
    
     @Override
    
    
     public void onDestroy() {
    
    
     super.onDestroy();
    
    
     malevich.closeCache();
    
    
     }
    
    
    
    

    BIT  disp  位图  
    相关文章