mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-10 03:28:49 +00:00
feat(cv): 新增通过URL创建Image的方法
- 添加fromUrl(URL url)方法,支持通过URL对象加载图片 - 添加fromUrl(String urlString)方法,支持通过URL字符串加载图片 - 增加对URL为空参数的参数校验并抛出异常 - 实现了使用URL打开输入流并转换为Image的功能 - 提升了SmartImageFactory的灵活性和易用性
This commit is contained in:
@@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.file.Path;
|
||||
@@ -147,6 +148,19 @@ public class SmartImageFactory {
|
||||
return ImageFactory.getInstance().fromInputStream(inputStream);
|
||||
}
|
||||
|
||||
public Image fromUrl(URL url) throws IOException {
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("URL 不能为空");
|
||||
}
|
||||
try (InputStream inputStream = url.openStream()) {
|
||||
return ImageFactory.getInstance().fromInputStream(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
public Image fromUrl(String urlString) throws IOException {
|
||||
return this.fromUrl(new URL(urlString));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user