调用meitu秀秀.so文件实现美图功能

时间:2022-12-12 21:39:53

本文属于实战系列,是对《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);
}

项目布局如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="process"
android:text="美化" /> <ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/button" /> </RelativeLayout>

调用meitu秀秀.so文件实现美图功能

(图片来自于网络)

代码如下:

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); }
}

获取更多C语言与算法相关知识,关注公众号:“csuanfa”

调用meitu秀秀.so文件实现美图功能