remove dependency from ToolkitImage in Image comonentent

This commit is contained in:
bancika
2020-03-31 12:59:38 +02:00
parent 276ad57521
commit d62ce646ed
5 changed files with 19 additions and 3 deletions
Binary file not shown.
@@ -0,0 +1,17 @@
package org.diylc.awt;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
public class ImageUtils {
public static BufferedImage ToBufferedImage(Image image) {
BufferedImage bi =
new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return bi;
}
}
@@ -32,6 +32,7 @@ import javax.swing.ImageIcon;
import org.apache.poi.util.IOUtils;
import org.diylc.appframework.miscutils.IconImageConverter;
import org.diylc.awt.ImageUtils;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
@@ -44,8 +45,6 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.PercentEditor;
import sun.awt.image.ToolkitImage;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -147,7 +146,7 @@ public class Image extends AbstractTransparentComponent<Void> {
public ImageIcon getImage() {
if (image != null) {
// when loading old files, convert the stored image to byte array and then then discard it, we won't be needing it anymore
BufferedImage bi = ((ToolkitImage) image.getImage()).getBufferedImage();
BufferedImage bi = ImageUtils.ToBufferedImage(image.getImage());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(bi, "png", baos);
Binary file not shown.
Binary file not shown.