2021 5 19

云相册下载图片:

    public String advancedGeneral(Bitmap bitmap,String photoid) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general";
        try {
            byte[] imgData =BitmapToBytes(bitmap);
            // 本地文件路径
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");
            String param = "image=" + imgParam;
            String result = postGeneralUrl(url, param,token,photoid);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
  private byte[] BitmapToBytes(Bitmap bitmap){
        ByteArrayOutputStream baos=new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
        return baos.toByteArray();
    }
 public void setphoto()   //显示照片
    {
        LinearLayout linearLayout=getView().findViewById(R.id.linear);
        String[] a=null;
//        updownphoto u=new updownphoto(photo[1].split("\+"),handler_photo);
//        u.run(getActivity());
        for(int i=0;i<time.length;i++)
        {
            TextView textView = new TextView(getActivity());
            textView.setText(time[i]);
            linearLayout.addView(textView);
            if(i+1<photo.length) {
                a = photo[i + 1].split("\+");
                for (int j = 0; j < a.length; j = j + 4) {
                    TableLayout tableLayout = new TableLayout(getActivity());
                    TableRow tableRow = new TableRow(getActivity());
                    tableLayout.addView(tableRow);
                    linearLayout.addView(tableLayout);
                    for (int p = j; p < p + 4; p++) {
                        if (p == a.length) break;
                        ImageView imageView = new ImageView(getActivity());
                        imageView.setPadding(20, 20, 20, 20);
                        tableRow.addView(imageView);
                        update(a[p], imageView);
                    }
                }
            }else{
                Toast.makeText(getActivity(),"点击加号上传照片",Toast.LENGTH_SHORT).show();
            }
        }
    }
原文地址:https://www.cnblogs.com/fuxw4971/p/14910547.html