由於許多時候需要使用到對圖片的一些裁剪特效,所以寫了一個簡單的幫助庫,目前只是簡單對形狀做了一些處理,後續會進行優化改進,加入更多的效果。
一.各種處理效果
第一張圖片是原圖,後續依次是裁剪圓形、正方形、橢圓、弧形、矩形、圓角矩形、隨意路徑,既可以從源圖片中央開始裁剪,指定裁剪比例,也可以在源圖片指定任意的矩形位置開始裁剪,並且可以指定是否添加邊框,邊框顏色和寬度。
二.添加依賴
在project的build.gradle文件中添加
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
在module的build.gradle文件中添加
dependencies {
implementation 'com.github.MingYueChunQiu:BitmapHelper:0.1'
}
三.Bitmap的使用
//先獲取對圖片形狀處理的幫助類
BitmapShapeHelper helper = BitmapHelperFactory.newBitmapShapeHelper();
//在BitmapShapeHelper 裏目前提供了對7種形狀的處理
@NonNull
public BitmapCircleShapeable getBitmapCircleShapeImpl() {
return new BitmapCircleShape();
}
@NonNull
public BitmapSquareShapeable getBitmapSquareShapeImpl() {
return new BitmapSquareShape();
}
@NonNull
public BitmapRoundRectShapeable getBitmapRoundRectShapeImpl() {
return new BitmapRoundRectShape();
}
@NonNull
public BitmapPathShapeable getBitmapPathShapeImpl() {
return new BitmapPathShape();
}
@NonNull
public BitmapArcShapeable getBitmapArcShapeImpl() {
return new BitmapArcShape();
}
@NonNull
public BitmapRectShapeable getBitmapRectShapeImpl() {
return new BitmapRectShape();
}
@NonNull
public BitmapOvalShapeable getBitmapOvalShapeImpl() {
return new BitmapOvalShape();
}
更多詳細內容請至本文末尾項目地址看項目demo使用或庫源碼。
四.結語
項目的GitHub地址是https://github.com/MingYueChunQiu/BitmapHelper,碼雲的項目地址是https://gitee.com/MingYueChunQiu/BitmapHelper。如果有什麼不足或建議,歡迎反饋。