preview with 50% alpha
This commit is contained in:
parent
ea9de93db8
commit
65b433b138
@ -5,8 +5,24 @@ import com.mortennobel.imagescaling.ResampleOp;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.WritableRaster;
|
||||||
|
|
||||||
public class ImageResizer {
|
public class ImageHelper {
|
||||||
|
|
||||||
|
public static BufferedImage COPY(final BufferedImage source) {
|
||||||
|
final BufferedImage copy = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
|
||||||
|
source.copyData(copy.getRaster());
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ALPHA(final BufferedImage image, final double alpha) {
|
||||||
|
final WritableRaster raster = image.getAlphaRaster();
|
||||||
|
for (int y = 0; y < raster.getHeight(); y++) {
|
||||||
|
for (int x = 0; x < raster.getWidth(); x++) {
|
||||||
|
raster.setSample(x, y, 0, raster.getSample(x, y, 0) * alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static BufferedImage RESIZE(final BufferedImage image, final int maxWidth, final int maxHeight) {
|
public static BufferedImage RESIZE(final BufferedImage image, final int maxWidth, final int maxHeight) {
|
||||||
final Point size = fitInsideBox(image, maxWidth, maxHeight);
|
final Point size = fitInsideBox(image, maxWidth, maxHeight);
|
||||||
@ -11,7 +11,7 @@ import java.io.IOException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static de.ph87.kindermalen.ImageResizer.RESIZE;
|
import static de.ph87.kindermalen.ImageHelper.RESIZE;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Getter
|
@Getter
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static de.ph87.kindermalen.ImageResizer.RESIZE;
|
import static de.ph87.kindermalen.ImageHelper.*;
|
||||||
import static de.ph87.kindermalen.tool.stamp.ListHelper.SYNC;
|
import static de.ph87.kindermalen.tool.stamp.ListHelper.SYNC;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -36,6 +36,9 @@ public class StampTool extends Tool {
|
|||||||
|
|
||||||
private BufferedImage prepared;
|
private BufferedImage prepared;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private BufferedImage preview;
|
||||||
|
|
||||||
public StampTool() {
|
public StampTool() {
|
||||||
super("Stempel");
|
super("Stempel");
|
||||||
final List<File> files = scan(STAMPS_DIR);
|
final List<File> files = scan(STAMPS_DIR);
|
||||||
@ -86,9 +89,11 @@ public class StampTool extends Tool {
|
|||||||
if (this.stamp == null || stamp.getOriginal() == null) {
|
if (this.stamp == null || stamp.getOriginal() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.prepared = RESIZE(stamp.getOriginal(), size, size);
|
prepared = RESIZE(stamp.getOriginal(), size, size);
|
||||||
|
preview = COPY(prepared);
|
||||||
|
ALPHA(preview, 0.5);
|
||||||
|
ALPHA(prepared, alpha);
|
||||||
log.info("Stamp prepared: {}", stamp.getName());
|
log.info("Stamp prepared: {}", stamp.getName());
|
||||||
// TODO apply alpha
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -110,9 +115,4 @@ public class StampTool extends Tool {
|
|||||||
destination.getGraphics().drawImage(prepared, point.intX() - prepared.getWidth() / 2, point.intY() - prepared.getHeight() / 2, null);
|
destination.getGraphics().drawImage(prepared, point.intX() - prepared.getWidth() / 2, point.intY() - prepared.getHeight() / 2, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BufferedImage getPreview() {
|
|
||||||
return prepared;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user