編輯:關於Android編程
本文屬於實戰系列,是對《Android C代碼回調java方法》等文的實踐,調用meitu秀秀的libmtimage-jni.so文件來實現圖片的美化功能
首先反編譯得到/libmtimage-jni.so文件和JNI文件
新建項目,將/libmtimage-jni.so文件拷貝到libs文件夾下,新建JNI文件並拷貝代碼,並導入loadLibrary
package com.mt.mtxx.image; public class JNI { static{ System.loadLibrary("mtimage-jni"); } public native void AutoColor(byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3, int paramInt4); public native void AutoColorLevel(byte[] paramArrayOfByte, int paramInt1, int paramInt2, boolean paramBoolean); public native void AutoConstrast(byte[] paramArrayOfByte, int paramInt1, int paramInt2); public native void AutoWhiteBalance(byte[] paramArrayOfByte, int paramInt1, int paramInt2); public native void BackWeak(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, int paramInt1, int paramInt2, int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt3, byte[] paramArrayOfByte3, int paramInt4, int paramInt5); public native void BackWeak2(byte[] paramArrayOfByte1, int paramInt1, int paramInt2, int paramInt3, int paramInt4, byte[] paramArrayOfByte2, int paramInt5, int paramInt6); public native void BackWeakLine(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, int[] paramArrayOfInt3, int[] paramArrayOfInt4, float paramFloat, int paramInt3, int paramInt4); public native void BackWeakOne(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, int paramInt3, int paramInt4, byte[] paramArrayOfByte, int paramInt5, int paramInt6); public native void CColorBalance(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4, byte[] paramArrayOfByte, int paramInt5, int paramInt6); public native void ColorModeEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2); public native void CompositeColorEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void DrawEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2); public native void ExclusionEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void ExclusionEx2(byte[] paramArrayOfByte, byte paramByte1, byte paramByte2, byte paramByte3, double paramDouble); public native void FaceBeauty(int[] paramArrayOfInt, int paramInt1, int paramInt2, int paramInt3); public native void FaceBeautyRelease(); public native void FrameXCBK(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, int paramInt3); public native void GaussIIRBlurBrush(int[] paramArrayOfInt, int paramInt1, int paramInt2, int paramInt3, int paramInt4); public native void GaussIIRBlurImage(byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3, int paramInt4); public native double GetDegreeByPoints(int paramInt1, int paramInt2, int paramInt3, int paramInt4); public native void Grayscale(byte[] paramArrayOfByte, int paramInt1, int paramInt2); public native void HardlightEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void ImageColorBurnEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2); public native void ImageDarkenEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void ImageExclusionEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void ImageLightenEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void ImageNormalEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void ImageOverlayEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void ImageScreenEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void ImageSoftLightEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void LOMO1(int[] paramArrayOfInt1, int paramInt1, int paramInt2, int[] paramArrayOfInt2); public native void LOMO2(int[] paramArrayOfInt1, int paramInt1, int paramInt2, int[] paramArrayOfInt2); public native void LightEnEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void MakeAllTransparent(byte[] paramArrayOfByte, int paramInt1, int paramInt2); public native void MultipleEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void NoiseEx(byte[] paramArrayOfByte, long paramLong); public native void NormalEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void OldImage(byte[] paramArrayOfByte1, int paramInt1, int paramInt2, byte[] paramArrayOfByte2, int paramInt3, int paramInt4); public native void PinLightEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2); public native void PtChangeByRotate(byte[] paramArrayOfByte, double paramDouble1, double paramDouble2, double paramDouble3); public native void RGBtoXYZ(byte paramByte1, byte paramByte2, byte paramByte3, byte[] paramArrayOfByte); public native void RGBtoYIQ(byte paramByte1, byte paramByte2, byte paramByte3, byte[] paramArrayOfByte); public native void RGBtoYUV(byte paramByte1, byte paramByte2, byte paramByte3, byte[] paramArrayOfByte); public native void Resample(byte[] paramArrayOfByte1, int paramInt1, int paramInt2, int paramInt3, byte[] paramArrayOfByte2, int paramInt4, int paramInt5); public native void SSkinbeautify(int[] paramArrayOfInt, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, double paramDouble); public native void ScreenEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void SetBackWeakRadius(byte[] paramArrayOfByte, int paramInt1, int paramInt2); public native void SetColorImage(byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5); public native void SetGrayScaleEx(byte[] paramArrayOfByte); public native void Sharp(int[] paramArrayOfInt, int paramInt1, int paramInt2, float paramFloat1, float paramFloat2); public native void SharpPreview(int[] paramArrayOfInt, int paramInt1, int paramInt2, float paramFloat1, float paramFloat2); public native void SharpPreviewRelease(); public native void ShiftRGBEx(byte[] paramArrayOfByte, byte paramByte1, byte paramByte2, byte paramByte3); public native void SkinWhite(int[] paramArrayOfInt, int paramInt1, int paramInt2, int paramInt3); public native void SoftLightEx(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, double paramDouble); public native void StyleBaoColor(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleCinnamon(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleClassic(int[] paramArrayOfInt, int paramInt1, int paramInt2, double paramDouble); public native void StyleClassicStudio(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleEP1(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleEP2(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleElegant(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleElegantNew(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleFP1(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleFP2(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleFilm(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleGP1(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, byte[] paramArrayOfByte, int paramInt3); public native void StyleGP2(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, byte[] paramArrayOfByte, int paramInt3); public native void StyleImpression(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleJapanese(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleLomoAP1(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, byte[] paramArrayOfByte, int paramInt3); public native void StyleLomoAP2(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, byte[] paramArrayOfByte, int paramInt3); public native void StyleLomoB(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleLomoBrightRed(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleLomoC(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleLomoChristmas(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleLomoHDR(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void StyleMilk1(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleMilk2(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleMilk3(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleMilk4(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleOldPhoto(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2); public native void StyleOldPhotoP1(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, byte[] paramArrayOfByte, int paramInt3); public native void StyleOldPhotoP2(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, byte[] paramArrayOfByte, int paramInt3); public native void StyleRetro(int[] paramArrayOfInt, int paramInt1, int paramInt2); public native void XYZtoRGB(byte paramByte1, byte paramByte2, byte paramByte3, byte[] paramArrayOfByte); public native void YIQtoRGB(byte paramByte1, byte paramByte2, byte paramByte3, byte[] paramArrayOfByte); public native void YUVtoRGB(byte paramByte1, byte paramByte2, byte paramByte3, byte[] paramArrayOfByte); public native int add(int paramInt, byte paramByte); public native byte[] deal(byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3, int paramInt4, String paramString); }
項目布局如下:
(圖片來自於網絡)
代碼如下:
package com.wuyudong.wuxiuxiu; import com.mt.mtxx.image.JNI; import android.os.Bundle; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.view.View; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView image; private JNI jni; private Bitmap bm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.image); bm = BitmapFactory.decodeFile("sdcard/awaiyi.jpg"); image.setImageBitmap(bm); jni = new JNI(); } public void process(View v) { int width = bm.getWidth(); int height = bm.getHeight(); int[] pixels = new int[width * height]; // getPixels執行之後pixels數組就被修改了 pixel中保存了bm的顏色信息 bm.getPixels(pixels, 0, width, 0, 0, width, height); // StyleLomoB運行後,pixel的顏色信息已經被修改 修改成特效處理後的顏色信息 jni.StyleLomoB(pixels, width, height); // 用處理好的像素數組 創建一張新的圖片就是經過特效處理的 Bitmap bm2 = Bitmap.createBitmap(pixels, width, height, bm.getConfig()); image.setImageBitmap(bm2); } }
一、前言上篇說清楚了Unity和Android調用的方式,但很多實際接入的部分沒有講的很詳細,因為重頭在這篇,會詳細講述具體接入Android SDK的方式,和怎麼去做一
Android 5.0 Lollipop是Android發布的最具意義的一個版本,這樣說的一個很重要的原因是Material Design的引入,一個新的設計語言刷新了整
從一接觸Android開始,就聽說了消息機制,那時候對消息機制的理解也只是看看別人博客,了解一些概念和相關的類而已,並沒有深入的去了解和探究。直到最近,重新過了一遍消息
上一篇文章我們介紹了安卓(Android)手機拔號盤下隱藏的功能,除了這些隱藏的暗碼以外,各大手機廠商也在安卓(Android)手機裡設置了自己的工程模式,