1. 程式人生 > >對Bitmap進行各種形狀效果處理工具

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

由於許多時候需要使用到對圖片的一些裁剪特效,所以寫了一個簡單的幫助庫,目前只是簡單對形狀做了一些處理,後續會進行優化改進,加入更多的效果。

一.各種處理效果

在這裡插入圖片描述

第一張圖片是原圖,後續依次是裁剪圓形、正方形、橢圓、弧形、矩形、圓角矩形、隨意路徑,既可以從源圖片中央開始裁剪,指定裁剪比例,也可以在源圖片指定任意的矩形位置開始裁剪,並且可以指定是否新增邊框,邊框顏色和寬度。

二.新增依賴

在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使用或庫原始碼。

四.結語