!12 feat(cv): 新增通过URL创建Image的方法

Merge pull request !12 from 黄政棋/dev
This commit is contained in:
Adam
2025-12-04 10:06:56 +00:00
committed by Gitee

View File

@@ -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));
}
}