1. 从byte[]得到Image
- private static Image createImage(byte[] imageBytes) {
- Image image = null;
- try {
- ByteArrayInputStream bais = new ByteArrayInputStream(imageBytes);
- image = new Image(null, bais);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return image;
- }
2. 从Image得到byte[]
public static byte[] getImageBytes(Image image) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
imageLoader.save(baos, image.type);
byte[] imageByteArray = baos.toByteArray();
try {
baos.close();
} catch (Exception e) {
e.printStackTrace();
}
return imageByteArray;
}