-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cn.nbhope.imageproxylib.transform; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapShader; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
|
||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; | ||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; | ||
|
||
/** | ||
* @Description 将图片转换成圆形 | ||
* Created by EthanCo on 2016/8/30. | ||
*/ | ||
public class CircleTransform extends BitmapTransformation { | ||
|
||
public CircleTransform(Context context) { | ||
super(context); | ||
} | ||
|
||
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) { | ||
if (source == null) return null; | ||
|
||
int size = Math.min(source.getWidth(), source.getHeight()); | ||
int x = (source.getWidth() - size) / 2; | ||
int y = (source.getHeight() - size) / 2; | ||
|
||
// TODO this could be acquired from the pool too | ||
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size); | ||
|
||
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); | ||
if (result == null) { | ||
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); | ||
} | ||
|
||
Canvas canvas = new Canvas(result); | ||
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint | ||
.ANTI_ALIAS_FLAG); | ||
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader | ||
.TileMode.CLAMP)); | ||
float r = size / 2f; | ||
canvas.drawCircle(r, r, r, paint); | ||
return result; | ||
} | ||
|
||
@Override | ||
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { | ||
return circleCrop(pool, toTransform); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return getClass().getName(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Apr 19 14:48:38 CST 2016 | ||
#Wed Sep 07 13:31:46 CST 2016 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.1" | ||
|
||
defaultConfig { | ||
applicationId "com.ethanco.mybehaviortest_08" | ||
minSdkVersion 15 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:24.1.1' | ||
compile 'com.android.support:design:24.1.1' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in D:\SDK/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |