mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix pic for word
This commit is contained in:
@@ -199,10 +199,10 @@ public class BeanPath implements Serializable{
|
||||
}
|
||||
if (bean instanceof Map) {
|
||||
// 只支持String为key的Map
|
||||
MapUtil.getAny((Map<String, ?>) bean, unwrapedKeys);
|
||||
return MapUtil.getAny((Map<String, ?>) bean, unwrapedKeys);
|
||||
} else {
|
||||
final Map<String, Object> map = BeanUtil.beanToMap(bean);
|
||||
MapUtil.getAny(map, unwrapedKeys);
|
||||
return MapUtil.getAny(map, unwrapedKeys);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@@ -399,12 +399,12 @@ public class ImgUtil {
|
||||
if (srcWidth % destWidth == 0) {
|
||||
cols = srcWidth / destWidth;
|
||||
} else {
|
||||
cols = (int) Math.floor((double)srcWidth / destWidth) + 1;
|
||||
cols = (int) Math.floor((double) srcWidth / destWidth) + 1;
|
||||
}
|
||||
if (srcHeight % destHeight == 0) {
|
||||
rows = srcHeight / destHeight;
|
||||
} else {
|
||||
rows = (int) Math.floor((double)srcHeight / destHeight) + 1;
|
||||
rows = (int) Math.floor((double) srcHeight / destHeight) + 1;
|
||||
}
|
||||
// 循环建立切片
|
||||
Image tag;
|
||||
@@ -1248,6 +1248,18 @@ public class ImgUtil {
|
||||
return read(new ByteArrayInputStream(imageBytes));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将图片对象转换为InputStream形式
|
||||
*
|
||||
* @param image 图片对象
|
||||
* @param imageType 图片类型
|
||||
* @return Base64的字符串表现形式
|
||||
* @since 4.2.4
|
||||
*/
|
||||
public static ByteArrayInputStream toStream(Image image, String imageType) {
|
||||
return IoUtil.toStream(toBytes(image, imageType));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将图片对象转换为Base64形式
|
||||
*
|
||||
@@ -1257,9 +1269,21 @@ public class ImgUtil {
|
||||
* @since 4.1.8
|
||||
*/
|
||||
public static String toBase64(Image image, String imageType) {
|
||||
return Base64.encode(toBytes(image, imageType));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将图片对象转换为bytes形式
|
||||
*
|
||||
* @param image 图片对象
|
||||
* @param imageType 图片类型
|
||||
* @return Base64的字符串表现形式
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public static byte[] toBytes(Image image, String imageType) {
|
||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
write(image, imageType, out);
|
||||
return Base64.encode(out.toByteArray());
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -99,4 +99,13 @@ public class BeanPathTest {
|
||||
Object result = pattern.get(tempMap);
|
||||
Assert.assertEquals(2, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMapTest () {
|
||||
BeanPath pattern = BeanPath.create("userInfo[id, photoPath]");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> result = (Map<String, Object>)pattern.get(tempMap);
|
||||
Assert.assertEquals(1, result.get("id"));
|
||||
Assert.assertEquals("yx.mm.com", result.get("photoPath"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user