2016年2月16日 星期二

產生json檔

//生成一個JsonArrayJSONArray JArray=new JSONArray();

for (int img_count = 0 ; img_count<image_count ;img_count++) {
    //生成一個JSONObject
    Log.e("Count",String.valueOf(img_count));
    img_adress[img_count] = way.get(img_count);
    ex_img = BitmapFactory.decodeFile(img_adress[img_count]);
    ex_img2 = Bitmap.createBitmap(8, 8, Bitmap.Config.ARGB_8888);

    Utils.bitmapToMat(ex_img, ex_Mat);
    Imgproc.resize(ex_Mat, ex_Mat2, dsize);//调用Imgproc的Resize方法,进行图片缩放    Imgproc.cvtColor(ex_Mat2, ex_Mat, Imgproc.COLOR_BGR2GRAY);//灰階    Utils.matToBitmap(ex_Mat, ex_img2);
    avr_hash = gethash(ex_img2);

    try {
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("path",img_adress[img_count]);
        jsonObj.put("code",avr_hash);
        JArray.put(jsonObj);
    }catch (JSONException e){ //JSONException 要用對才行
        Log.e("JSON/P/C","failed");
    }
    Log.e("你弄的JsonArray",JArray.toString());




E/你弄的JsonArray﹕ [{"path":"\/mnt\/sdcard\/Pictures\/picture.jpg","code":"bb4cbbbb44bb4444"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151203_083401.jpg","code":"44bb4cbfbb44bb44"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151203_083402.jpg","code":"4bb4fbf4b44bb44b"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151203_083405.jpg","code":"44fb74bbbb44bb44"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151203_083405_1.jpg","code":"84fbf0843b84003b"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151203_083406.jpg","code":"4bb47bbcb44bb44b"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151217_022336.jpg","code":"7474bb44bbbb44bb"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151217_022338.jpg","code":"b4b44bf47b4bb44b"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151217_022338_1.jpg","code":"43bc7373bc43bcbc"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151217_022339.jpg","code":"444cbb44bbbb44bb"},{"path":"\/mnt\/sdcard\/DCIM\/Camera\/IMG_20151217_022339_1.jpg","code":"444cbf44bbbb44bb"},


沒有留言:

張貼留言