Java源码示例:com.facepp.http.PostParameters

示例1
public static void detect(final Bitmap bm, final CallBack callBack) {
	new Thread(new Runnable() {

		@Override
		public void run() {
			// request

			try {
				HttpRequests requests = new HttpRequests(KEY, 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 params = new PostParameters();
				params.setImg(arrays);
				JSONObject jsonObject = requests.detectionDetect(params);

				// Log
				Log.i("TAG", jsonObject.toString());

				if (callBack != null) {
					callBack.success(jsonObject);
				}
			} catch (FaceppParseException e) {
				e.printStackTrace();
				if (callBack != null) {
					callBack.error(e);
				}
			}

		}
	}).start();

}
 
示例2
public void detect(final Bitmap image) {

            new Thread(new Runnable() {

                public void run() {
                    HttpRequests httpRequests = new HttpRequests(
                            "8a6935b89012418fad0e9b3328bbeba9",
                            "WQN_MfSnt5Frtmy0XYeKJ8fh1xIVAmo_", true, false);
                    // Log.v(TAG, "image size : " + img.getWidth() + " " +
                    // img.getHeight());

                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    float scale = Math.min(
                            1,
                            Math.min(600f / img.getWidth(),
                                    600f / img.getHeight()));
                    Matrix matrix = new Matrix();
                    matrix.postScale(scale, scale);

                    Bitmap imgSmall = Bitmap.createBitmap(img, 0, 0,
                            img.getWidth(), img.getHeight(), matrix, false);
                    // Log.v(TAG, "imgSmall size : " + imgSmall.getWidth() + " "
                    // + imgSmall.getHeight());

                    imgSmall.compress(Bitmap.CompressFormat.JPEG, 100, stream);
                    byte[] array = stream.toByteArray();

                    try {
                        // detect
                        JSONObject result = httpRequests
                                .detectionDetect(new PostParameters()
                                        .setImg(array));
                        // finished , then call the callback function
                        if (callback != null) {
                            callback.detectResult(result);
                        }
                    } catch (FaceppParseException e) {
                        e.printStackTrace();
                        FindHowOldAct.this.runOnUiThread(new Runnable() {
                            public void run() {
                                SystemUtils.checkNetWork(FindHowOldAct.this);
                                textView.setText("error.");
                            }
                        });
                    }

                }
            }).start();
        }
 
示例3
public static void recogenition(final File file){

        new Thread(new Runnable() {
            @Override
            public void run() {
                HttpRequests httpRequests = new HttpRequests(Global.FACEPP_KEY, Global.FACEPP_SECRET);
                PostParameters postParameters = new PostParameters().setImg(file).setAttribute("all");

                try {
                   // postParameters.getMultiPart().writeTo(System.out);

                    JSONObject result =   httpRequests.detectionDetect(postParameters);

                    System.out.println(result.toString());



                } catch (FaceppParseException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }