Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CPPAlien committed Jul 14, 2016
1 parent 21d91b2 commit f9dd2cc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repositories{
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.CPPAlien:DaVinci:1.2.5'
compile 'com.github.CPPAlien:DaVinci:1.3.0'
}
```

Expand Down Expand Up @@ -118,11 +118,11 @@ getHttpRequest().timeOut(int timesOutMs)
```
getHttpRequest().maxRetries(int maxRetries)
```
* 设置加载图片大小,图片长宽按比例缩小为设定的maxpix大小
* 设置加载图片大小,图片长宽按比例缩放为设定的maxpix大小,并且缓存到本地
```
getImageLoader().resize(int maxPix).load(...)
```
**注:设置图片大小有如下限制:1,对Gif无效;2,只能按比例缩小图片,无法放大图片;3,只能在第一次加载时有效(因为图片加载成功后都会缓存到本地,为了效率考虑,后续显示该图片都从缓存中拿取,不再进行大小裁剪)。**
**注:对Gif无效;**

* 使用POST方法加载图片,body中为post方法体
```
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/cn/hadcn/davinci_example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
DaVinci.with(this).getImageLoader().load("http://7xlkhg.com2.z0.glb.qiniucdn.com/qbi_cry.gif").into(image1);

Glide.with(this).load("http://7xlkhg.com2.z0.glb.qiniucdn.com/qbi_cry.gif").into(image2);
DaVinci.with(this).getImageLoader().load( "http://photo.enterdesk.com/2011-11-26/enterdesk.com-1CB20FDF5918603F9264E5BFDC4DF691.jpg").resize(400).into(image3);
DaVinci.with(this).getImageLoader().load("http://photo.enterdesk.com/2011-11-26/enterdesk.com-1CB20FDF5918603F9264E5BFDC4DF691.jpg").resize(400).into(image3);
image2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down Expand Up @@ -95,7 +95,7 @@ public void onVinciUploadFailed(String reason) {
});

DaVinci.with().addThreadPool("one", 1);
DaVinci.with().tag("one").getImageLoader().load("http://y3.ifengimg.com/fashion_spider/dci_2012/02/20a78c36cc31225b1a7efa89f566f591.jpg").into(image3);
DaVinci.with().tag("one").getImageLoader().load("http://y3.ifengimg.com/fashion_spider/dci_2012/02/20a78c36cc31225b1a7efa89f566f591.jpg").resize(600).into(image3);

OutputStream out;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final void execute(String requestBody) {
return;
}

ByteBuffer byteBuffer = mImageCache.getBitmap(Util.generateKey(mImageUrl));
ByteBuffer byteBuffer = mImageCache.getBitmap(Util.generateKey(mImageUrl + mMaxSize));

if ( byteBuffer != null ) {
byte[] bytes = byteBuffer.array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ public void putImage(String name, ByteBuffer bitmap) {
}
}

public boolean isCached(String name) {
String key = Util.generateKey(name);
if ( key.isEmpty() ) throw new RuntimeException("key is invalid");

return mImageCache.getBitmap(name) != null;
}

public VinciImageLoader load(String url) {
mReadImageTask = new ReadImageTask(mContext, mImageCache, mImageLoader, url);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,13 @@ public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)

int bHeight = bitmap.getHeight();
int bWidth = bitmap.getWidth();
int scaleWidth = 0;
int scaleHeight = 0;
if ( mMaxSize > 0 ) {
if ( bWidth > mMaxSize) {
scaleWidth = mMaxSize;
scaleHeight = (scaleWidth * bHeight) / bWidth;
bitmap = Bitmap.createScaledBitmap(bitmap, scaleWidth, scaleHeight, false);
}
if ( scaleHeight > mMaxSize) {
scaleHeight = mMaxSize;
scaleWidth = (scaleHeight * bWidth) / bHeight;
bitmap = Bitmap.createScaledBitmap(bitmap, scaleWidth, scaleHeight, false);
if ( bWidth > bHeight ) {
int otherSize = (mMaxSize * bHeight) / bWidth;
bitmap = Bitmap.createScaledBitmap(bitmap, mMaxSize, otherSize, false);
} else {
int otherSize = (mMaxSize * bWidth) / bHeight;
bitmap = Bitmap.createScaledBitmap(bitmap, otherSize, mMaxSize, false);
}
}
mImageView.setImageBitmap(bitmap);
Expand All @@ -92,7 +87,7 @@ public void onErrorResponse(VolleyError error) {
}

private void cacheImage(String url, ByteBuffer byteBuffer) {
String key = Util.generateKey(url);
String key = Util.generateKey(url + mMaxSize);
if ( key.isEmpty() ) return;
mImageCache.putBitmap(key, byteBuffer);
}
Expand Down

0 comments on commit f9dd2cc

Please sign in to comment.