use of java.awt.image.AffineTransformOp in project runelite by runelite.
the class PuzzleSolverOverlay method getRotatedImage.
private BufferedImage getRotatedImage(BufferedImage image, double theta) {
AffineTransform transform = new AffineTransform();
transform.rotate(theta, image.getWidth() / 2, image.getHeight() / 2);
AffineTransformOp transformOp = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
return transformOp.filter(image, null);
}
use of java.awt.image.AffineTransformOp in project AozoraEpub3 by hmdev.
the class JCoverImagePanel method createPreviewImage.
/**
* プレビュー用の小さい画像を生成
*/
private void createPreviewImage(double scale) {
BufferedImage previewImage = new BufferedImage((int) Math.round(this.bookInfo.coverImage.getWidth() * scale), (int) Math.round(this.bookInfo.coverImage.getHeight() * scale), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = previewImage.createGraphics();
try {
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, previewImage.getWidth(), previewImage.getHeight());
AffineTransformOp ato = new AffineTransformOp(AffineTransform.getScaleInstance(scale, scale), AffineTransformOp.TYPE_BICUBIC);
g2.drawImage(this.bookInfo.coverImage, ato, 0, 0);
} finally {
g2.dispose();
}
this.previewImage = previewImage;
}
use of java.awt.image.AffineTransformOp in project AozoraEpub3 by hmdev.
the class JCoverImagePanel method getModifiedImage.
/**
* 編集された表紙を取得
*/
public BufferedImage getModifiedImage(double coverW, double coverH) {
try {
// 表紙なし
if (this.bookInfo.coverImage == null)
return null;
double scale = Math.min((double) this.getWidth() / bookInfo.coverImage.getWidth(), (double) this.getHeight() / this.bookInfo.coverImage.getHeight());
if (this.visibleWidth <= 0)
this.visibleWidth = this.getWidth();
// トリミングと幅変更なしで、表紙サイズならnullを返す
if (this.scale == scale && this.visibleWidth == this.getWidth()) {
// if ()
return null;
}
if (this.previewImage == null)
this.createPreviewImage(this.scale);
// 縮尺に合せてリサイズ 大きければ縮小
double coverScale = 1;
if (coverW > 0 && coverH > 0)
coverScale = Math.min(coverW / this.visibleWidth, coverH / this.getHeight()) * this.scale;
else if (coverW > 0)
coverScale = (coverW / this.visibleWidth) * this.scale;
else if (coverH > 0)
coverScale = (coverH / this.getHeight()) * this.scale;
coverW = Math.min(coverW, this.bookInfo.coverImage.getWidth() * coverScale);
coverH = Math.min(coverH, this.bookInfo.coverImage.getHeight() * coverScale);
if (coverScale > 1) {
coverW /= coverScale;
coverH /= coverScale;
coverScale = 1;
}
coverW *= this.visibleWidth / Math.min(this.getWidth(), this.previewImage.getWidth());
int x = 0;
if (this.visibleWidth < this.previewImage.getWidth())
x = (int) Math.round(this.offsetX * coverW / this.visibleWidth);
int y = 0;
if (this.getHeight() < this.previewImage.getHeight())
y = (int) Math.round(this.offsetY * coverH / this.getHeight());
BufferedImage coverImage = new BufferedImage((int) coverW, (int) coverH, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = coverImage.createGraphics();
try {
// リサイズのatoとoffset指定でdrawImage
AffineTransformOp ato = new AffineTransformOp(AffineTransform.getScaleInstance(coverScale, coverScale), AffineTransformOp.TYPE_BICUBIC);
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, (int) coverW, (int) coverH);
g2.drawImage(this.bookInfo.coverImage, ato, x, y);
} finally {
g2.dispose();
}
return coverImage;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of java.awt.image.AffineTransformOp in project digilib by robcast.
the class BioFormatsDocuImage method scale.
@Override
public void scale(double scaleX, double scaleY) throws ImageOpException {
logger.debug("scale: " + scaleX);
/* for downscaling in high quality the image is blurred first */
if ((scaleX <= 0.5) && (quality > 1)) {
int bl = (int) Math.floor(1 / scaleX);
// blur(bl);
}
/* then scaled */
AffineTransformOp scaleOp = new AffineTransformOp(AffineTransform.getScaleInstance(scaleX, scaleY), renderHint);
img = scaleOp.filter(img, null);
logger.debug("scaled to " + img.getWidth() + "x" + img.getHeight() + " img=" + img);
// invalidate image size
imageSize = null;
}
use of java.awt.image.AffineTransformOp in project digilib by robcast.
the class ImageLoaderDocuImage method rotate.
/*
* (non-Javadoc)
* @see digilib.image.DocuImageImpl#rotate(double)
*/
public void rotate(double angle) throws ImageOpException {
logger.debug("rotate: " + angle);
// setup rotation
double rangle = Math.toRadians(angle);
// center of rotation is center of image
double w = img.getWidth();
double h = img.getHeight();
double x = (w / 2);
double y = (h / 2);
AffineTransform trafo = AffineTransform.getRotateInstance(rangle, x, y);
AffineTransformOp rotOp = new AffineTransformOp(trafo, renderHint);
// rotate bounds to see how much of the image would be off screen
Rectangle2D rotbounds = rotOp.getBounds2D(img);
double xoff = rotbounds.getX();
double yoff = rotbounds.getY();
if (Math.abs(xoff) > epsilon || Math.abs(yoff) > epsilon) {
// move image back on screen
logger.debug("move rotation: xoff=" + xoff + " yoff=" + yoff);
trafo.preConcatenate(AffineTransform.getTranslateInstance(-xoff, -yoff));
rotOp = new AffineTransformOp(trafo, renderHint);
}
// transform image
img = rotOp.filter(img, null);
logger.debug("rotated: " + img);
// invalidate image size
imageSize = null;
}
Aggregations