編輯:關於 Android 程式設計
這篇文章說明如何透過 JNI 載入 libmtimage-jni.so,並在 Java 端呼叫原生影像處理方法。使用前要確認 so 與裝置 ABI 相符,並把檔案放到正確的 jniLibs 或 libs 對應位置。
JNI 類別會在 static 區塊中呼叫 System.loadLibrary 載入原生庫,並宣告多個 native 方法。常見方法包含 AutoColor、AutoConstrast、StyleLomoB、SkinWhite、Sharp 等。
public class JNI {
static {
System.loadLibrary("mtimage-jni");
}
public native void StyleLomoB(int[] pixels, int width, int height);
public native void SkinWhite(int[] pixels, int width, int height, int value);
public native void Sharp(int[] pixels, int width, int height, float value1, float value2);
}
版面配置可以包含一個 Button 與 ImageView。按下按鈕後,把 Bitmap 的像素取出,傳給 native 方法處理,再用處理後的像素建立新的 Bitmap。

int width = bm.getWidth();
int height = bm.getHeight();
int[] pixels = new int[width * height];
bm.getPixels(pixels, 0, width, 0, 0, width, height);
jni.StyleLomoB(pixels, width, height);
Bitmap bm2 = Bitmap.createBitmap(pixels, width, height, bm.getConfig());
image.setImageBitmap(bm2);
這種做法的核心是 Bitmap 與 int 像素陣列之間的轉換。native 方法修改 pixels 後,Java 端再用新陣列建立圖片,即可看到美化效果。
Android 四大組件之 Service:生命週期與兩種啟動方式詳解
Service 簡介Service 是 Android 四大組件之一,通常用於沒有 UI 介面、需要長期在後台執行的任務,即使程式退出,後台任務依然持續運行,典型場景比如
Android 底部導航實作:BottomBar、ViewPager 與 Fragment 整合
底部導航是許多 Android 應用的常見設計,尤其在需要快速切換主要功能時特別有用。本文示範如何結合 BottomBar、ViewPager 與 Fragment,完成
Android 編譯系統(二):使用 mm 編譯單一模組
Android 編譯系統與傳統 Makefile 遞歸編譯不同,它將各模組視為相對獨立的單元。mm 指令可用來編譯目前目錄下對應的單一模組,大幅縮短開發時的編譯時間。 m
iOS Auto Layout 設計與實作入門
Auto Layout 是 iOS 介面開發中重要的相對佈局系統。它透過約束描述元件之間的關係,使畫面能適配不同尺寸與解析度。本文整理在 Storyboard 與 xib