ソースを参照

orc图片处理修改

master
yangpeilai 3日前
コミット
ede506ff56

+ 13
- 9
zhywpt-service-ats/src/main/java/cn/com/taiji/ats/manager/ocr/ImageCompressManagerImpl.java ファイルの表示

@@ -5,7 +5,6 @@ import cn.com.taiji.common.manager.net.http.ServiceHandleException;
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.http.util.Asserts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@@ -14,6 +13,7 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
@@ -122,12 +122,11 @@ public class ImageCompressManagerImpl extends AbstractManager implements ImageCo
}

private BufferedImage downloadImg(String imageUrl) throws ServiceHandleException {
logger.info("图片下载地址: {}", imageUrl);
HttpURLConnection connection = null;
try {
// 使用URL类打开连接
URL url = new URL(imageUrl);
// 强制转换为内网113 minio

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");

// 确保响应码是200(OK)
@@ -135,12 +134,17 @@ public class ImageCompressManagerImpl extends AbstractManager implements ImageCo
throw new IOException("HTTP error code: " + connection.getResponseCode());
}

// 使用ImageIO.read()从URL连接的输入流中读取BufferedImage
return ImageIO.read(connection.getInputStream());
try (InputStream stream = connection.getInputStream()) {
return ImageIO.read(stream);
}

} catch (Exception e) {
logger.info("",e);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("图片地址格式错误");
logger.error("处理图片时发生意外错误: {}", imageUrl, e);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("处理图片时发生错误");
} finally {
if (connection != null) {
connection.disconnect();
}
}
}


読み込み中…
キャンセル
保存