GithubHelp home page GithubHelp logo

winziyuan / sketch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from panpf/sketch

0.0 1.0 0.0 230.29 MB

Sketch是Android上一个强大且全面的图片加载器,支持GIF,手势缩放以及分块显示超大图片。Sketch is a powerful and comprehensive image loader on Android, with support for GIF, gesture zooming, block display super large image

License: Apache License 2.0

Java 100.00%

sketch's Introduction

Logo Sketch Image Loader

Platform Android Arsenal License Logs Version API QQ Group

English version of the README.md

Sketch 是 Android 上一款强大且全面的图片加载器,除了图片加载的必备功能外,还支持 GIF,手势缩放、分块显示超大图片、自动纠正图片方向、显示视频缩略图等功能

示例 APP

SampleApp

扫描二维码下载示例 APP,也可点击直接下载(Click download APK)

支持的特性

  • 多种URI支持. 支持http://或https://asset://content://file:///sdcard/sample.jpg或/sdcard/sample.jpgdrawable://data:image/或data:img/等6种URI
  • 支持gif图. 集成了android-gif-drawable 1.2.6可以方便的显示gif图片,感谢koral--
  • 支持手势缩放. 支持手势缩放功能,在PhotoView的基础上进行了优化,增加了滚动条,定位等功能
  • 支持分块显示超大图. 支持分块显示超大图功能,从此再大的图片也不怕了
  • 支持三级缓存. 通过LruMemoryCache、LruDiskCache复用图片,加快显示时间;通过LruBitmapPool复用Bitmap,减少因GC而造成的卡顿
  • 支持纠正图片方向. 可纠正方向不正的图片,并且分块显示超大图功能也支持,仅限jpeg格式的图片
  • 支持读取APK图标. 支持直接读取本地APK文件的图标或根据包名和版本号读取已安装APP的图标
  • 支持Base64图片. 支持解析 Base64 格式的图片
  • 支持各种列表. 在各种列表(ListView、RecyclerView)中循环使用不错位,并且不占用setTag()方法
  • 自动防止加载过大Bitmap 可通过maxSize来控制加载到内存的图片的尺寸,默认为ImageView的layout_width和layout_height或屏幕的宽高
  • 独家TransitionDrawable支持. 独家支持任意尺寸的两张图片使用TransitionDrawable过渡显示,保证不变形
  • 只加载或只下载. 除了display()方法可以显示图片之外,你还可以通过load()方法只加载图片到内存中或通过download()方法只下载图片到本地
  • 移动网络下暂停下载. 内置了移动网络下暂停下载图片的功能,你只需开启即可
  • 自动选择合适的Bitmap.Config. 根据图片的MimeType自动选择合适的Bitmap.Config,减少内存浪费,例如对于JPEG格式的图片就会使用Bitmap.Config.RGB_565解码
  • 特殊文件预处理. 通过ImagePreprocessor可对特殊文件(例如多媒体文件)进行预处理,提取出其包含的图片,读取APK文件的图标就是通过这个功能实现的
  • 强大且灵活的自定义. 可自定义下载、缓存、解码、处理、显示、占位图等各个环节

支持的URI

Type Scheme Method In SketchImageView
File in network http://, https:// displayImage(String)
File in SDCard /, file:// displayImage(String)
Content Provider content:// displayContentImage(Uri)
Asset in app asset:// displayAssetImage(String)
Resource in app resource:// displayResourceImage(int)
Base64 data:image/, data:/img/ displayImage(String)

支持的图片类型

Image Type Supported Version
jpeg API
png API
gif API
bmp API
webp API

开始使用

导入 Sketch

1.在 app 的 build.gradle 文件的 dependencies 节点中加入依赖

compile 'me.xiaopan:sketch:$sketch_version'

请自行替换 $sketch_version 为最新的版本 Version (不要"v")

如果需要播放 GIF 就添加 sketch-gif 的依赖

compile 'me.xiaopan:sketch-gif:$sketch_gif_version'

请自行替换$sketch_gif_version 为最新的版本 Version (不要"v")

Android Studio 会自动合并 AAR 中所包含的权限和混淆配置

2.如果需要兼容 API 13 (Android 3.2) 及以下的版本,那么需要在 Application 中调用释放缓存的方法(Android 4.0以上能直接通过Context注册并回调)

public class MyApplication extends Application {    

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            Sketch.with(getBaseContext()).onTrimMemory(level);
        }
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            Sketch.with(getBaseContext()).onLowMemory();
        }
    }
}

使用 SketchImageView 显示图片

SketchImageView sketchImageView = (SketchImageView) findViewById(R.id.image_main);

// display image from net
sketchImageView.displayImage("http://t.cn/RShdS1f");

// display image from SDCard
sketchImageView.displayImage("/sdcard/sample.jpg");
sketchImageView.displayImage("file:///sdcard/sample.jpg");

// display resource drawable
sketchImageView.displayResourceImage(R.drawable.sample);

// display image from asset
sketchImageView.displayAssetImage("sample.jpg");

// display image from content provider
sketchImageView.displayContentImage(Uri.parse("content://com.android.gallery/last"));

// display base64 image
sketchImageView.displayImage("data:image/jpeg;base,/9j/4QaO...U7T/in//Z");

// display apk/app icon
sketchImageView.displayImage("/sdcard/google_play.apk");
sketchImageView.displayInstalledAppIcon("com.tencent.qq", 210);

更多功能

基础功能:

进一步提升用户体验:

更多:

特别感谢

koral - android-gif-drawable

chrisbanes - PhotoView

bumptech - glide (BitmapPool)

联系我

  • Email

  • QQ Group

License

Copyright (C) 2013 Peng fei Pan <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

sketch's People

Contributors

panpf avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.