fix pic for word

This commit is contained in:
Looly
2020-03-20 09:21:18 +08:00
parent 249f20d0ed
commit 81c2850cfc
6 changed files with 74 additions and 7 deletions

View File

@@ -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 {

View File

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

View File

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