mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
call graphics dispose after use
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user