NDK實現的圖片處理工具

Introduction

通過jni編寫c++代碼來實現圖片的基本處理,使用 NDKProcessImage 可以對圖片的一些基本操作,可以用來實現對bitmap的對比度調節、亮度調節、旋轉、鏡像、高斯模糊、yuv和rgb格式互轉等。

Features

我們對Markdown編輯器進行了一些功能拓展與語法支持,除了標準的Markdown編輯器功能,我們增加了如下幾點新功能,幫助你用它寫博客:

  1. 支持對比度調節;
  2. 支持亮度調節;
  3. 支持旋轉;
  4. 支持鏡像;
  5. 支持高斯模糊功能;
  6. 支持yuv和rgb數據互轉。

Getting started

在項目的根節點的 build.gradle 中添加如下代碼

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

在項目的 build.gradle 中添加

dependencies {
    implementation 'com.github.Kebiiii:NDKProcessImage:v1.0.2'
}

Usage

  1. 設置bitmap的亮度和對比度:
  • 亮度範圍:0-1.0f
  • 對比度範圍:-1.0f-1.0f
mBitmap = NativeImageUtils.brightnessContrastChange(mOriginalBitmap, brightness, contrast);
imageView.setImageBitmap(mBitmap);
  1. 對圖片的argb數據圖像加深:相當於亮度設置爲0.2f對比度設置0.2f:
int[] result = NativeImageUtils.deepImage(buffer, mBitmap.getWidth(), mBitmap.getHeight());
  1. argb2Yuv: 圖片的argb數據轉爲yuv格式:
byte[] yuvData = NativeImageUtils.argb2Yuv(data,width,height);
  1. yuv420sp2rgb: 圖片的yuv格式轉爲rgb數據:
int[] data = NativeImageUtils.yuv420sp2rgb(yuvData,width,height);
  1. gaussBlur: 對bitmap圖片進行高斯模糊處理:
  • radius: 模糊半徑
mBitmap = NativeImageUtils.gaussBlur(mBitmap,30);
imageView.setImageBitmap(mBitmap);
  1. rotateBitmap: 對bitmap圖片90度旋轉順時針:
mBitmap = NativeImageUtils.rotateBitmap(mBitmap);
imageView.setImageBitmap(mBitmap);
  1. convertBitmap: 對bitmap圖片上下鏡像處理:
mBitmap = NativeImageUtils.convertBitmap(mBitmap);
imageView.setImageBitmap(mBitmap);
  1. mirrorBitmap: 對bitmap圖片左右鏡像處理:
mBitmap = NativeImageUtils.mirrorBitmap(mBitmap);
imageView.mirrorBitmap(mBitmap);

NDKProcessImage 圖片處理工具混淆配置

-keep class com.kebii.utils.**{*;}

關於我

github地址:

鏈接: https://github.com/Kebiiii/NDKProcessImage/.

demo界面:
在這裏插入圖片描述

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