call graphics dispose after use

This commit is contained in:
Egor.Ushakov
2015-02-11 20:41:53 +03:00
parent 40f69a7112
commit e1533c70ae
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,15 +23,17 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* Created by Egor on 04.10.2014.
* @author egor
*/
public class ImageSerializer {
public static byte[] imageToBytes(Image image) throws IOException {
//noinspection UndesirableClassUsage
BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.drawImage(image, 0, 0, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bi, "png", baos);
g.dispose();
return baos.toByteArray();
}
@@ -42,14 +44,17 @@ public class ImageSerializer {
return null;
}
/** @noinspection unused*/
public static byte[] iconToBytesPreviewNormal(Icon icon) throws IOException {
return iconToBytesPreview(icon, 16);
}
/** @noinspection unused*/
public static byte[] iconToBytesPreviewRetina(Icon icon) throws IOException {
return iconToBytesPreview(icon, 32);
}
/** @noinspection unused*/
public static byte[] iconToBytes(Icon icon) throws IOException {
return imageToBytes(toImage(icon));
}