- 将“XJGARSDKDemoApp-Android-master.zip”解压,解压后的文件夹中有名为“XJGArSdkDemoApp”的文件夹。(注意:解压的路径全文中不得有中文)。
- 使用Android Studio打开“XJGArSdkDemoApp”的文件夹所对应的项目。
- 若用户除了“XJGARSDKDemoApp-Android-master.zip”文件之外,还获得了更新的动态库文件(文件类型为aar)或者更新的License字段,那么执行以下3.1至3.3步骤。
- 将最新的动态库文件(文件类型为aar)放入文件夹“XJGArSdkDemoApp”文件夹路径\XJGArSdkDemoApp\app\libs中
- 将项目内的HomeActivity.java文件中的licenseText的内容换成最新的License字段
- 将“XJGArSdkDemoApp”文件夹路径\XJGArSdkDemoApp\app\build.gradle中字段“compile(name:'xjgarsdklibrary-release-9.1.0-2018-02-07', ext:'aar')”的对应文件名更新为最新的aar文件的文件名
运行项目的方式有两种,一是在安卓手机上测试,二是在计算机的安卓模拟器上测试。因为本APP需要调用手机摄像头,而安卓模拟器无法调用摄像头,因此不推荐第二种测试方式(安卓模拟器)。
1 将安卓手机(本文所用手机为华为荣耀V10手机)的开发模式打开。具体步骤如下:
1.1 在手机标准界面找到“设置”
1.2 打开设置,下拉选项,找到“关于手机”
1.3 在关于手机选项里,找到“版本号”,连点7次
1.4 之后会提示您,您已处于开发者模式,我们会在设置选项里,看到开发者模式这一项。
1.5 在“设置”-》“开发人员选项”中,打开“USB调试”开关。个别手机还需要开启““仅充电”模式下允许ADB调试”开关
1.6 将安卓手机通过USB线连接到电脑。
1.7 在安卓手机的提示界面选择“仅充电”选项
1.8 使用Android Studio打开项目,点击运行按钮
1.9 选择安卓手机作为调试平台
http://www.xiaojigou.cn 首页-》开发包-》说明文档-》XJGARSDK说明文档
注意:SDK中各个函数需要在单一的线程中调用。
- 初始化
####初始化方法:
private static native boolean XJGARSDKInitialization(String licenseText, String userName, String companyName);
- context参数为获取SD卡里存放SDK模型(model)的目
- licenseText参数为license key的字符串值
- userName参数为该licence key对应的用户名
- companyName参数为该license key对应的公司名
注:license相关的参数均需要提前申请
####销毁方法: public static native boolean XJGARSDKCleanUP();
- 使用人脸整形
####大眼:
public static native boolean XJGARSDKSetBigEyeParam (int eyeParam);
- eyeParam参数为0-100,数值越大眼睛越大
####瘦脸:
public static native boolean XJGARSDKSetThinChinParam (int chinParam);
- chinParam参数为0-100,数值越大脸部下吧越瘦
####红润:
public static native boolean XJGARSDKSetRedFaceParam(int redFaceParam);
- redFaceParam参数为0-100,数值越大脸部皮肤越红润
####美白:
public static native boolean XJGARSDKSetWhiteSkinParam(int whiteSkinParam);
- whiteSkinParam参数为0-100,数值越大脸部皮肤越白
####磨皮:
public static native boolean XJGARSDKSetSkinSmoothParam(int skinSmoothParam);
- skinSmoothParam参数为0-100, 数值越大越皮肤越光滑
- 使用人脸滤镜
SDK启动时默认不使用滤镜
####切换滤镜:
public static native boolean XJGARSDKChangeFilter(String filterTypeName);
- filterTypeName参数为滤镜名字,目前可选的滤镜有6种,分别是冰冷,健康,祖母绿,怀旧, 蜡笔, 常青,填入“无”不使用滤镜;
- 在某些中文输入有问题的状况下可以使用英文参数输入,6种滤镜分别为:"filter_cool", "filter_Healthy","filter_emerald","filter_nostalgia","filter_crayon", "filter_evergreen"。填入"filter_none",不使用滤镜。
- 使用人脸道具
####显示贴纸:
public static native boolean XJGARSDKSetShowStickerPapers(boolean bShowStickPaper);
- bShowStickPaper参数 为true时,显示贴纸
####是否显示LandMark
public static native boolean XJGARSDKSetShowLandMarks(boolean bShowLandMarks);
####切换贴纸:
public static native boolean XJGARSDKChangeStickpaper(String stickPaperName);
- stickPaperName参数为贴纸名称,目前可选的贴纸见StickerPapers子文件夹,每个文件夹的名称均是贴纸名称
- 图片视频流处理
####初始化OpenGL环境:如果用户没有opengl环境,则创建一个虚拟的opengl环境
public static native boolean XJGARSDKInitOpenglEnvironment(int width, int height);
- width参数为输入图片宽度
- height参数为输入图片高度
####销毁OpenGL环境
public static native boolean XJGARSDKDestroyOpenglEnvironment();
####释放OpenGL占用的所有资源
public static native boolean XJGARSDKReleaseAllOpenglResources();
####设置贴纸根路径
public static native boolean XJGARSDKSetRootDirectory( String rootDirectory);
- 参数rootDirctory为路径名称
####设置模式
public static native boolean XJGARSDKSetOptimizationMode(int mode);
- mode参数为0代表视频,1代表图片
####对图片进行美颜处理
public static native void XJGARSDKRenderImage(byte[] rgbInputImageData , int width, int height);
- 参数rgbInputImageData为3通道的RGB图像
- 参数width为图像宽度
- 参数height为图像高度
- 返回:即经过美颜,滤镜,道具处理后的图像
####对Bitmap图像进行美颜
public static Bitmap XJGARSDKRenderImage(Bitmap bitmap,boolean bFlipYAxis)
- 参数bitmap为输入图像
- 返回:美颜后的bitmap图片
####对Bitmap图像进行美颜并设定是否水平翻转
public static Bitmap XJGARSDKRenderImage(Bitmap bitmap,boolean bFlipYAxis)
- 参数bitmap为输入图像
- 参数bFlipYAxis为是否进行水平翻转
- 返回:美颜后的bitmap图片,当bFlipYAxis为true时为水平翻转后的美颜图片
####在Opengl屏幕缓存中存储最后渲染的结果
public static native void XJGARSDKRenderImage(byte[] rgbInputImageData , int width, int height);
- 参数rgbInputImageData为3通道的RGB图像
- 参数width为图像宽度
- 参数height为图像高度
####获取opengl texture的地址
public static native void XJGARSDKRenderImageToGLTex(byte[] rgbInputImageData, int width, int height, int[] outputTexId);
- 参数rgbInputImageData为3通道的RGB图像
- 参数width为图像宽度
- 参数height为图像高度
- 返回:opengl texture的地址
####获取opengl的texture
public static native int XJGARSDKRenderGLTexToGLTex( int inputTexId, int width, int height );
- 参数rgbInputImageData为3通道的RGB图像
- 参数width为图像宽度
- 参数height为图像高度
- 返回:opengl的texture
####将Opengl texture放到opengl屏幕缓存中
public static native void XJGARSDKRenderGLTexture( int inputTexId, int width, int height );
• 参数inputTexId为opengl的texuture地址
• 参数width为texture的宽度
• 参数height为texture的高度
- 其他
####显示各种算法的执行效率(以LOG的方式在android studio 控制台中打印显示)
public static native boolean XJGARSDKSetShowPerformanceStatic(boolean bPerformanceStatic);
####通过android应用初始化SDK
public static boolean XJGARSDKInitialization(Context context,String licenseText,String userName,String companyName);
- context参数为获取SD卡里存放SDK模型(model)的目录
- licenseText参数为license key的字符串值
- userName参数为该licence key对应的用户名
- ompanyName参数为该license key对应的公司名
注:license相关的参数均需要提前申请
####复制贴纸到应用目录
public static boolean XJGARSDKCopyStickerPaperes( Context context);
- context参数为android应用程序上下文,函数会获取APP的私有存储空间目录并将模型贴纸等复制到目的
####获取应用内部路径
public static String getPrivateResDataDir(Context context);
- context参数为android应用程序上下文,函数会获取APP的私有存储空间目录
####从assets目录中复制整个文件夹内容
public static void copyFilesFromAssets(Context context, String oldPath, String newPath);
- 参数context为使用android应用程序上下文对象
- 参数oldPath为源文件路径,如/original/path
- 参数newPath为复制后的路径,如/target/path
####水平翻转bitmap图片
public static Bitmap FlipBitmapYAxis(Bitmap a, int width, int height);
- 参数a为原始bitmap图片
- 参数width为图片宽度
- 参数height为图片高度
####获取Bitmap图片的grb值
public static byte[] rgbValuesFromBitmap(Bitmap bitmap, boolean bFlipYAxis);
- 参数bitmap为输入图片
- 参数bFlipYAxis为是否对图像进行水平翻转
- 返回:(翻转后的)Bitmap图片的rgb值
####通过本地资源文件ID加载本地资源图片
public static Bitmap getResourceBitmap(Context context, int ResID);
- 参数context为android应用程序上下文对象
- 参数ResID为本地资源图片的ID
- 返回:加载到的Bitmap图片
####通过本地资源文件名称加载本地资源图片
public static Bitmap getResourceBitmap(Context context, String ResName);
- 参数context为android应用程序上下文对象
- 参数ResName为本地资源文件的名称
- 返回:加载到的Bitmap图片
####通过文件URL加载本地资源图片
public static Bitmap getLoacalBitmap(String url);
- 参数url为本地资源文件的url
- 返回:加载到的Bitmap图片
####通过http url加载服务器端资源图片
public static Bitmap getHttpBitmap(String url);
- 参数url服务器端的资源图片的http url
- 返回:加载到的Bitmap图片