提交 23c0f9d7 编写于 作者: 如梦技术's avatar 如梦技术 🐛

完善 mica-core ImageUtil

上级 cdb86c04
......@@ -62,12 +62,22 @@ public class ImageUtil {
}
/**
* 读取图片
* 读取图片,http 或者 file 地址
*
* @param url 图片链接地址
* @return BufferedImage
*/
public static BufferedImage read(String url) {
return isHttpUrl(url) ? readUrl(url) : read(new File(url));
}
/**
* 读取图片
*
* @param url 图片链接地址
* @return BufferedImage
*/
public static BufferedImage readUrl(String url) {
try {
return ImageIO.read(new URL(url));
} catch (IOException e) {
......@@ -144,7 +154,7 @@ public class ImageUtil {
}
/**
* 写出图片
* 写出图片为 byte 数组
*
* @param im RenderedImage to be written.
* @param formatName a String containing the informal name of the format.
......@@ -161,4 +171,19 @@ public class ImageUtil {
}
}
/**
* 写出图片为 InputStream
*
* @param im RenderedImage to be written.
* @param formatName a String containing the informal name of the format.
* @return false if no appropriate writer is found.
*/
public static ByteArrayInputStream writeAsStream(RenderedImage im, String formatName) {
return new ByteArrayInputStream(writeAsBytes(im, formatName));
}
private static boolean isHttpUrl(String text) {
return text.startsWith("http://") || text.startsWith("https://");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册