mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-10-05 18:53:20 +08:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4c23e38206 | ||
|
ffae37274c | ||
|
0c6f696ba7 | ||
|
3aea08abaa | ||
|
883c131ad6 | ||
|
ee1f533999 | ||
|
68a9097962 | ||
|
6269999abc | ||
|
7e93ccd9af | ||
|
07b7d24e13 | ||
|
ca648cbc7d | ||
|
67ac3e31a4 | ||
|
1534573e8f | ||
|
a5487ade83 | ||
|
62abca0b1e | ||
|
a6bbdb0694 | ||
|
2f75284dd4 | ||
|
5772f60c61 |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,6 +1,27 @@
|
|||||||
Change Log
|
Change Log
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
Version 1.0.4 *(2015-02-13)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Bug fix : remove original bitmap resource recycling.
|
||||||
|
|
||||||
|
Version 1.0.3 *(2015-02-05)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Bug fix
|
||||||
|
|
||||||
|
Version 1.0.2 *(2015-02-04)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Refactor: use BimapPool
|
||||||
|
|
||||||
|
Version 1.0.1 *(2015-01-21)*
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
fix: Blur Transformation now woking at Android 4.3
|
||||||
|
add: GPUImage to Gradle dependency
|
||||||
|
|
||||||
Version 1.0.0 *(2015-01-12)*
|
Version 1.0.0 *(2015-01-12)*
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
|
@@ -32,8 +32,8 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'jp.wasabeef:glide-transformations:1.0.1'
|
compile 'jp.wasabeef:glide-transformations:1.0.4@aar'
|
||||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3@aar'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -53,9 +53,9 @@ def getKeyAliasPasswordProperty() {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':transformations')
|
compile project(':transformations')
|
||||||
// compile 'jp.wasabeef:glide-transformations:1.0.1'
|
// compile 'jp.wasabeef:glide-transformations:1.0.4'
|
||||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
||||||
compile 'com.android.support:appcompat-v7:+'
|
compile 'com.android.support:appcompat-v7:21.+'
|
||||||
compile 'com.android.support:recyclerview-v7:21.+'
|
compile 'com.android.support:recyclerview-v7:21.+'
|
||||||
compile 'com.github.bumptech.glide:glide:3.+'
|
compile 'com.github.bumptech.glide:glide:3.5.1'
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
VERSION_NAME=1.0.1
|
VERSION_NAME=1.0.5
|
||||||
VERSION_CODE=3
|
VERSION_CODE=5
|
||||||
GROUP=jp.wasabeef
|
GROUP=jp.wasabeef
|
||||||
ARTIFACT_ID=glide-transformations
|
ARTIFACT_ID=glide-transformations
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
compile 'com.github.bumptech.glide:glide:3.4.0'
|
compile 'com.github.bumptech.glide:glide:3.5.1'
|
||||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,23 +50,31 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
|||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
Bitmap outBitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(),
|
|
||||||
Bitmap.Config.ARGB_8888);
|
int width = source.getWidth();
|
||||||
Canvas canvas = new Canvas(outBitmap);
|
int height = source.getHeight();
|
||||||
|
|
||||||
|
Bitmap.Config config =
|
||||||
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
|
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(width, height, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
Canvas canvas = new Canvas(bitmap);
|
||||||
canvas.drawBitmap(source, 0, 0, null);
|
canvas.drawBitmap(source, 0, 0, null);
|
||||||
|
|
||||||
RenderScript rs = RenderScript.create(mContext);
|
RenderScript rs = RenderScript.create(mContext);
|
||||||
Allocation overlayAlloc = Allocation.createFromBitmap(rs, outBitmap);
|
Allocation overlayAlloc = Allocation.createFromBitmap(rs, bitmap);
|
||||||
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
|
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
|
||||||
blur.setInput(overlayAlloc);
|
blur.setInput(overlayAlloc);
|
||||||
blur.setRadius(mRadius);
|
blur.setRadius(mRadius);
|
||||||
blur.forEach(overlayAlloc);
|
blur.forEach(overlayAlloc);
|
||||||
overlayAlloc.copyTo(outBitmap);
|
overlayAlloc.copyTo(bitmap);
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
rs.destroy();
|
rs.destroy();
|
||||||
|
|
||||||
return BitmapResource.obtain(outBitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -45,14 +45,18 @@ public class ColorFilterTransformation implements Transformation<Bitmap> {
|
|||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
int height = source.getHeight();
|
int height = source.getHeight();
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
Bitmap.Config config =
|
||||||
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
|
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(width, height, config);
|
||||||
|
}
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
|
paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,7 @@ import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapShader;
|
import android.graphics.BitmapShader;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
|
||||||
public class CropCircleTransformation implements Transformation<Bitmap> {
|
public class CropCircleTransformation implements Transformation<Bitmap> {
|
||||||
@@ -42,25 +43,26 @@ public class CropCircleTransformation implements Transformation<Bitmap> {
|
|||||||
int width = (source.getWidth() - size) / 2;
|
int width = (source.getWidth() - size) / 2;
|
||||||
int height = (source.getHeight() - size) / 2;
|
int height = (source.getHeight() - size) / 2;
|
||||||
|
|
||||||
Bitmap squaredBitmap = Bitmap.createBitmap(source, width, height, size, size);
|
Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
|
||||||
if (squaredBitmap != source) {
|
if (bitmap == null) {
|
||||||
source.recycle();
|
bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP,
|
BitmapShader shader = new BitmapShader(source, BitmapShader.TileMode.CLAMP,
|
||||||
BitmapShader.TileMode.CLAMP);
|
BitmapShader.TileMode.CLAMP);
|
||||||
|
if (width != 0 || height != 0) {
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
matrix.setTranslate(-width, -height);
|
||||||
|
shader.setLocalMatrix(matrix);
|
||||||
|
}
|
||||||
paint.setShader(shader);
|
paint.setShader(shader);
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
|
|
||||||
float r = size / 2f;
|
float r = size / 2f;
|
||||||
canvas.drawCircle(r, r, r, paint);
|
canvas.drawCircle(r, r, r, paint);
|
||||||
|
|
||||||
squaredBitmap.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,9 +41,11 @@ public class CropSquareTransformation implements Transformation<Bitmap> {
|
|||||||
mWidth = (source.getWidth() - size) / 2;
|
mWidth = (source.getWidth() - size) / 2;
|
||||||
mHeight = (source.getHeight() - size) / 2;
|
mHeight = (source.getHeight() - size) / 2;
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
|
Bitmap.Config config =
|
||||||
if (bitmap != source) {
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
source.recycle();
|
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
|
@@ -51,6 +51,13 @@ public class CropTransformation implements Transformation<Bitmap> {
|
|||||||
mHeight = source.getHeight();
|
mHeight = source.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bitmap.Config config =
|
||||||
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
|
Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
|
||||||
|
}
|
||||||
|
|
||||||
float scaleX = (float) mWidth / source.getWidth();
|
float scaleX = (float) mWidth / source.getWidth();
|
||||||
float scaleY = (float) mHeight / source.getHeight();
|
float scaleY = (float) mHeight / source.getHeight();
|
||||||
float scale = Math.max(scaleX, scaleY);
|
float scale = Math.max(scaleX, scaleY);
|
||||||
@@ -61,10 +68,8 @@ public class CropTransformation implements Transformation<Bitmap> {
|
|||||||
float top = (mHeight - scaledHeight) / 2;
|
float top = (mHeight - scaledHeight) / 2;
|
||||||
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, source.getConfig());
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
canvas.drawBitmap(source, null, targetRect, null);
|
canvas.drawBitmap(source, null, targetRect, null);
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,12 @@ public class GrayscaleTransformation implements Transformation<Bitmap> {
|
|||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
int height = source.getHeight();
|
int height = source.getHeight();
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
Bitmap.Config config =
|
||||||
|
source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
|
||||||
|
Bitmap bitmap = mBitmapPool.get(width, height, config);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(width, height, config);
|
||||||
|
}
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
ColorMatrix saturation = new ColorMatrix();
|
ColorMatrix saturation = new ColorMatrix();
|
||||||
@@ -50,7 +55,6 @@ public class GrayscaleTransformation implements Transformation<Bitmap> {
|
|||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
|
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,10 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
|
|||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
int height = source.getHeight();
|
int height = source.getHeight();
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
if (bitmap == null) {
|
||||||
|
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
}
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
@@ -56,7 +59,6 @@ public class RoundedCornersTransformation implements Transformation<Bitmap> {
|
|||||||
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||||
canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin),
|
canvas.drawRoundRect(new RectF(margin, margin, width - margin, height - margin),
|
||||||
radius, radius, paint);
|
radius, radius, paint);
|
||||||
source.recycle();
|
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user