Android對Bitmap進行各種形狀裁剪效果處理工具

在新版本中提供了自定義功能,優化了項目框架。
由於許多時候需要使用到對圖片的一些裁剪特效,所以寫了一個簡單的幫助庫,目前只是簡單對形狀做了一些處理,後續會進行優化改進,加入更多的效果。

一.各種處理效果

在這裏插入圖片描述
在這裏插入圖片描述
第一張圖片是原圖,後續兩張依次是裁剪圓形、正方形、橢圓、弧形、矩形、圓角矩形、隨意路徑不進行偏移處理、隨意路徑進行偏移處理的正常與反向裁剪效果,既可以從源圖片中央開始裁剪,指定裁剪比例,也可以在源圖片指定任意的矩形位置開始裁剪,並且可以指定是否添加邊框,邊框顏色和寬度。

二.添加依賴

在project的build.gradle文件中添加

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

在module的build.gradle文件中添加

dependencies {
	        implementation 'com.github.MingYueChunQiu:BitmapHelper:0.1.4'
	}

三.Bitmap的使用

    //先獲取對圖片形狀處理的幫助類
    BitmapShapeHelper helper = BitmapHelperFactory.newBitmapShapeHelper();
    
    //在BitmapShapeHelper 裏目前提供了對7種形狀的處理
	@NonNull
    public BitmapCircleShapeHelper getBitmapCircleShapeHelper() {
        return new BitmapCircleShapeHelper();
    }

    @NonNull
    public BitmapCircleShapeHelper getBitmapCircleShapeHelper(BitmapCircleShapeable shapeable) {
        return new BitmapCircleShapeHelper(shapeable);
    }

    @NonNull
    public BitmapSquareShapeHelper getBitmapSquareShapeHelper() {
        return new BitmapSquareShapeHelper();
    }

    @NonNull
    public BitmapSquareShapeHelper getBitmapSquareShapeHelper(BitmapSquareShapeable shapeable) {
        return new BitmapSquareShapeHelper(shapeable);
    }

    @NonNull
    public BitmapRoundRectShapeHelper getBitmapRoundRectShapeHelper() {
        return new BitmapRoundRectShapeHelper();
    }

    @NonNull
    public BitmapRoundRectShapeHelper getBitmapRoundRectShapeHelper(BitmapRoundRectShapeable shapeable) {
        return new BitmapRoundRectShapeHelper(shapeable);
    }

    @NonNull
    public BitmapPathShapeHelper getBitmapPathShapeHelper() {
        return new BitmapPathShapeHelper();
    }

    @NonNull
    public BitmapPathShapeHelper getBitmapPathShapeHelper(BitmapPathShapeable shapeable) {
        return new BitmapPathShapeHelper(shapeable);
    }

    @NonNull
    public BitmapArcShapeHelper getBitmapArcShapeHelper() {
        return new BitmapArcShapeHelper();
    }

    @NonNull
    public BitmapArcShapeHelper getBitmapArcShapeHelper(BitmapArcShapeable shapeable) {
        return new BitmapArcShapeHelper(shapeable);
    }

    @NonNull
    public BitmapRectShapeHelper getBitmapRectShapeHelper() {
        return new BitmapRectShapeHelper();
    }

    @NonNull
    public BitmapRectShapeHelper getBitmapRectShapeHelper(BitmapRectShapeable shapeable) {
        return new BitmapRectShapeHelper(shapeable);
    }

    @NonNull
    public BitmapOvalShapeHelper getBitmapOvalShapeHelper() {
        return new BitmapOvalShapeHelper();
    }

    @NonNull
    public BitmapOvalShapeHelper getBitmapOvalShapeHelper(BitmapOvalShapeable shapeable) {
        return new BitmapOvalShapeHelper(shapeable);
    }

更多詳細內容請至本文末尾項目地址看項目demo使用或庫源碼。

四.結語

項目的GitHub地址是https://github.com/MingYueChunQiu/BitmapHelper,碼雲的項目地址是https://gitee.com/MingYueChunQiu/BitmapHelper。如果有什麼不足或建議,歡迎反饋。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章