Kaynağa Gözat

orc图片处理修改

master
yangpeilai 2 hafta önce
ebeveyn
işleme
ede506ff56

+ 13
- 9
zhywpt-service-ats/src/main/java/cn/com/taiji/ats/manager/ocr/ImageCompressManagerImpl.java Dosyayı Görüntüle

import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError;
import net.coobird.thumbnailator.Thumbnails; import net.coobird.thumbnailator.Thumbnails;
import org.apache.http.util.Asserts; import org.apache.http.util.Asserts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;


import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
} }


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

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


// 确保响应码是200(OK) // 确保响应码是200(OK)
throw new IOException("HTTP error code: " + connection.getResponseCode()); 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) { } 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();
}
} }
} }



Loading…
İptal
Kaydet