/**
   * 生成图片的实体
   *
   * <p>参数:视角
   */
  private PhotoEntity generatePhotoEntity(int flag) {
    PhotoEntity photoEntity = new PhotoEntity();

    JSONObject jsonObject = new JSONObject();
    try {
      JSONObject photoJsonObject = new JSONObject();

      PosEntity posEntity = getPosEntity(flag);
      String fileName = posEntity.getImageFileName();
      int index = PhotoLayout.photoIndex++;

      photoJsonObject.put("x", posEntity.getStartX());
      photoJsonObject.put("y", posEntity.getStartY());
      photoJsonObject.put("width", getBitmapWidth(AppCommon.photoDirectory, fileName));
      photoJsonObject.put("height", getBitmapHeight(AppCommon.photoDirectory, fileName));
      photoJsonObject.put("issueId", posEntity.getIssueId());
      photoJsonObject.put("comment", posEntity.getComment());

      jsonObject.put("Group", "frame");
      jsonObject.put("Part", getPart(flag));
      jsonObject.put("PhotoData", photoJsonObject);
      jsonObject.put("CarId", BasicInfoLayout.carId);
      jsonObject.put("UserId", UserInfo.getInstance().getId());
      jsonObject.put("Key", UserInfo.getInstance().getKey());
      jsonObject.put("Action", Action.MODIFY);
      jsonObject.put("Index", index);

      photoEntity =
          PhotoUtils.generatePhotoEntity(
              jsonObject, "结构缺陷", fileName, Action.MODIFY, index, posEntity.getComment());
    } catch (JSONException e) {
      Log.d(AppCommon.TAG, e.getMessage());
    }

    return photoEntity;
  }
  private void paint(PosEntity entity, Canvas canvas) {
    int type = entity.getType();

    switch (type) {
      case Common.BROKEN:
        // 计算半径
        int dx = Math.abs(entity.getEndX() - entity.getStartX());
        int dy = Math.abs(entity.getEndY() - entity.getStartY());
        int dr = (int) Math.sqrt(dx * dx + dy * dy);

        // 计算圆心
        int x0 = (entity.getStartX() + entity.getEndX()) / 2;
        int y0 = (entity.getStartY() + entity.getEndY()) / 2;

        canvas.drawCircle(x0, y0, dr / 2, getPaint(type));
        return;
      case Common.DIRTY:
        RectF rectF;

        // 如果Rect的right < left,或者bottom < top,则会画不出矩形
        // 为了修正这个,需要做点处理

        // 右下
        if (entity.getStartX() < entity.getEndX() && entity.getStartY() < entity.getEndY()) {
          rectF =
              new RectF(entity.getStartX(), entity.getStartY(), entity.getEndX(), entity.getEndY());
        }
        // 右上
        else if (entity.getStartX() < entity.getEndX() && entity.getStartY() > entity.getEndY()) {
          rectF =
              new RectF(entity.getStartX(), entity.getEndY(), entity.getEndX(), entity.getStartY());
        }
        // 左下
        else if (entity.getStartX() > entity.getEndX() && entity.getStartY() < entity.getEndY()) {
          rectF =
              new RectF(entity.getEndX(), entity.getStartY(), entity.getStartX(), entity.getEndY());
        }
        // 左上
        else if (entity.getStartX() > entity.getEndX() && entity.getStartY() > entity.getEndY()) {
          rectF =
              new RectF(entity.getEndX(), entity.getEndY(), entity.getStartX(), entity.getStartY());
        }
        // 重合或者默认
        else {
          rectF =
              new RectF(entity.getStartX(), entity.getStartY(), entity.getEndX(), entity.getEndY());
        }

        canvas.drawRect(rectF, getPaint(entity.getType()));
    }
  }