detect為什么沒有數(shù)據(jù)返回,直接跳到exception了
package aind.myapplication;
import android.graphics.Bitmap;
import android.util.Log;
import com.facepp.error.FaceppParseException;
import com.facepp.http.HttpRequests;
import com.facepp.http.PostParameters;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
/**
* Created by Administrator on 2016/2/25.
* Request(發(fā)送請(qǐng)求)
*/
public class faceppDetect {
? ?public interface CallBack {
? ? ? ?void success(JSONObject result);
? ? ? ?void error(FaceppParseException exception);
? ?}
? ?/**
? ? *傳入一張bitmap和callback接口
? ? */
? ?public static void detect(final Bitmap bm, final CallBack callback) {
? ? ? ?// 耗時(shí)操作
? ? ? ?new Thread(new Runnable() {
? ? ? ? ? ?@Override
? ? ? ? ? ?public void run() {
? ? ? ? ? ? ? ?try {
? ? ? ? ? ? ? ? ? ?/***
? ? ? ? ? ? ? ? ? ? * 將傳入的bitmap轉(zhuǎn)換為二進(jìn)制數(shù)組,并通過PostParameters進(jìn)行壓縮
? ? ? ? ? ? ? ? ? ? * 然后通過HttpRequests的detectionDetect()方法得到返回的JSONObject
? ? ? ? ? ? ? ? ? ? */
? ? ? ? ? ? ? ? ? ?HttpRequests requests = new HttpRequests(constant.KEY,
? ? ? ? ? ? ? ? ? ? ? ? ? ?constant.SECRET, true, true);
? ? ? ? ? ? ? ? ? ?Bitmap bmSmall = Bitmap.createBitmap(bm, 0, 0,
? ? ? ? ? ? ? ? ? ? ? ? ? ?bm.getWidth(), bm.getHeight());
? ? ? ? ? ? ? ? ? ?ByteArrayOutputStream stream = new ByteArrayOutputStream();
? ? ? ? ? ? ? ? ? ?bmSmall.compress(Bitmap.CompressFormat.JPEG, 100, stream);
? ? ? ? ? ? ? ? ? ?byte[] arrays = stream.toByteArray();
? ? ? ? ? ? ? ? ? ?PostParameters prameter = new PostParameters();
? ? ? ? ? ? ? ? ? ?prameter.setImg(arrays);
? ? ? ? ? ? ? ? ? ?JSONObject jsonObject = requests.detectionDetect();
? ? ? ? ? ? ? ? ? ?//將JSONObject數(shù)據(jù)toString后打印日志
? ? ? ? ? ? ? ? ? ?Log.e("TAG", jsonObject.toString());
? ? ? ? ? ? ? ? ? ?if (callback != null) {
? ? ? ? ? ? ? ? ? ? ? ?callback.success(jsonObject);
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?} catch (FaceppParseException e) {
? ? ? ? ? ? ? ? ? ?e.printStackTrace();
? ? ? ? ? ? ? ? ? ?if (callback != null) {
? ? ? ? ? ? ? ? ? ? ? ?callback.error(e);
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ?}).start();
? ?}
}
2016-04-12
?JSONObject jsonObject = requests.detectionDetect( ?prameter? ? ); ?
這句少個(gè)參數(shù)。