本文整理了Java中java.awt.geom.AffineTransform.getScaleInstance()
方法的一些代码示例,展示了AffineTransform.getScaleInstance()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AffineTransform.getScaleInstance()
方法的具体详情如下:
包路径:java.awt.geom.AffineTransform
类名称:AffineTransform
方法名:getScaleInstance
暂无
代码示例来源:origin: plantuml/plantuml
public EmptyImageBuilder(int width, int height, Color background, double dpiFactor) {
this(width * dpiFactor, height * dpiFactor, background);
if (dpiFactor != 1.0) {
g2d.setTransform(AffineTransform.getScaleInstance(dpiFactor, dpiFactor));
}
}
代码示例来源:origin: libgdx/libgdx
/**
* Draws the glyph to the given image, upscaled by a factor of {@link #scale}.
*
* @param image the image to draw to
* @param glyph the glyph to draw
*/
private void drawGlyph(BufferedImage image, Glyph glyph) {
Graphics2D inputG = (Graphics2D) image.getGraphics();
inputG.setTransform(AffineTransform.getScaleInstance(scale, scale));
// We don't really want anti-aliasing (we'll discard it anyway),
// but accurate positioning might improve the result slightly
inputG.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
inputG.setColor(Color.WHITE);
inputG.fill(glyph.getShape());
}
代码示例来源:origin: libgdx/libgdx
/**
* Draws the glyph to the given image, upscaled by a factor of {@link #scale}.
*
* @param image the image to draw to
* @param glyph the glyph to draw
*/
private void drawGlyph(BufferedImage image, Glyph glyph) {
Graphics2D inputG = (Graphics2D) image.getGraphics();
inputG.setTransform(AffineTransform.getScaleInstance(scale, scale));
// We don't really want anti-aliasing (we'll discard it anyway),
// but accurate positioning might improve the result slightly
inputG.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
inputG.setColor(Color.WHITE);
inputG.fill(glyph.getShape());
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static BufferedImage verticalFlip(BufferedImage original) {
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -original.getHeight());
AffineTransformOp transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
BufferedImage awtImage = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_BGR);
Graphics2D g2d = awtImage.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_SPEED);
g2d.drawImage(original, transformOp, 0, 0);
g2d.dispose();
return awtImage;
}
代码示例来源:origin: ivan-vasilev/neuralnetworks
@Override
public void addAugmentedImages(List<BufferedImage> images)
{
for (int i = 0, l = images.size(); i < l; i++)
{
BufferedImage source = images.get(i);
AffineTransform tx = AffineTransform.getScaleInstance(-1.0, 1.0);
tx.translate(-source.getWidth(), 0);
AffineTransformOp tr = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
images.add(tr.filter(source, null));
}
}
代码示例来源:origin: ivan-vasilev/neuralnetworks
@Override
public void addAugmentedImages(List<BufferedImage> images)
{
for (int i = 0, l = images.size(); i < l; i++)
{
BufferedImage source = images.get(i);
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -source.getHeight(null));
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
images.add(op.filter(source, null));
}
}
代码示例来源:origin: looly/hutool
/**
* 根据文字创建PNG图片
*
* @param str 文字
* @param font 字体{@link Font}
* @param backgroundColor 背景颜色
* @param fontColor 字体颜色
* @param out 图片输出地
* @throws IORuntimeException IO异常
*/
public static void createImage(String str, Font font, Color backgroundColor, Color fontColor, ImageOutputStream out) throws IORuntimeException {
// 获取font的样式应用在str上的整个矩形
Rectangle2D r = font.getStringBounds(str, new FontRenderContext(AffineTransform.getScaleInstance(1, 1), false, false));
int unitHeight = (int) Math.floor(r.getHeight());// 获取单个字符的高度
// 获取整个str用了font样式的宽度这里用四舍五入后+1保证宽度绝对能容纳这个字符串作为图片的宽度
int width = (int) Math.round(r.getWidth()) + 1;
int height = unitHeight + 3;// 把单个字符的高度+3保证高度绝对能容纳字符串作为图片的高度
// 创建图片
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Graphics g = image.getGraphics();
g.setColor(backgroundColor);
g.fillRect(0, 0, width, height);// 先用背景色填充整张图片,也就是背景
g.setColor(fontColor);
g.setFont(font);// 设置画笔字体
g.drawString(str, 0, font.getSize());// 画出字符串
g.dispose();
writePng(image, out);
}
代码示例来源:origin: looly/hutool
/**
* 根据文字创建PNG图片
*
* @param str 文字
* @param font 字体{@link Font}
* @param backgroundColor 背景颜色
* @param fontColor 字体颜色
* @param out 图片输出地
* @throws IORuntimeException IO异常
*/
public static void createImage(String str, Font font, Color backgroundColor, Color fontColor, ImageOutputStream out) throws IORuntimeException {
// 获取font的样式应用在str上的整个矩形
Rectangle2D r = font.getStringBounds(str, new FontRenderContext(AffineTransform.getScaleInstance(1, 1), false, false));
int unitHeight = (int) Math.floor(r.getHeight());// 获取单个字符的高度
// 获取整个str用了font样式的宽度这里用四舍五入后+1保证宽度绝对能容纳这个字符串作为图片的宽度
int width = (int) Math.round(r.getWidth()) + 1;
int height = unitHeight + 3;// 把单个字符的高度+3保证高度绝对能容纳字符串作为图片的高度
// 创建图片
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Graphics g = image.getGraphics();
g.setColor(backgroundColor);
g.fillRect(0, 0, width, height);// 先用背景色填充整张图片,也就是背景
g.setColor(fontColor);
g.setFont(font);// 设置画笔字体
g.drawString(str, 0, font.getSize());// 画出字符串
g.dispose();
writePng(image, out);
}
代码示例来源:origin: plantuml/plantuml
private static AffineTransformation createSimple(String value) {
Matcher m = rotate.matcher(StringUtils.trin(value));
if (m.find()) {
final double angle = Double.parseDouble(m.group(1));
return new AffineTransformation(AffineTransform.getRotateInstance(angle * Math.PI / 180.0));
}
m = shear.matcher(value);
if (m.find()) {
final double shx = Double.parseDouble(m.group(1));
final double shy = Double.parseDouble(m.group(2));
return new AffineTransformation(AffineTransform.getShearInstance(shx, shy));
}
m = translate.matcher(value);
if (m.find()) {
final double tx = Double.parseDouble(m.group(1));
final double ty = Double.parseDouble(m.group(2));
return new AffineTransformation(AffineTransform.getTranslateInstance(tx, ty));
}
m = scale.matcher(value);
if (m.find()) {
final double scalex = Double.parseDouble(m.group(1));
final double scaley = Double.parseDouble(m.group(2));
return new AffineTransformation(AffineTransform.getScaleInstance(scalex, scaley));
}
m = color.matcher(value);
if (m.find()) {
return new AffineTransformation(new AffineTransform());
}
return null;
}
代码示例来源:origin: igniterealtime/Openfire
final AffineTransform scale = AffineTransform.getScaleInstance( (double) targetDimension / (double) targetWidth, (double) targetDimension / (double) targetHeight );
final Graphics2D g = resizedAvatar.createGraphics();
g.drawRenderedImage( avatar, scale );
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Resizes the image to the given width and height.
* @param source
* the source image (this remains untouched, the new image instance is created)
* @param width
* the target image width
* @param height
* the target image height
* @return the resized image
*/
public static Image resizeTo(Image source, int width, int height) {
BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0);
double scaleX = width / (double) sourceImage.getWidth();
double scaleY = height / (double) sourceImage.getHeight();
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
BufferedImage scaledImage = bilinearScaleOp.filter(sourceImage, new BufferedImage(width, height, sourceImage.getType()));
return ImageUtils.toJmeImage(scaledImage, source.getFormat());
}
代码示例来源:origin: org.apache.poi/poi
trans.concatenate(AffineTransform.getRotateInstance(style.getRotation()*2.0*Math.PI/360.0));
trans.concatenate(
AffineTransform.getScaleInstance(1, fontHeightMultiple)
);
bounds = layout.getOutline(trans).getBounds();
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
AffineTransform trans = AffineTransform.getScaleInstance(1, -1);
trans.translate(0, -img.getHeight(null));
AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -img.getHeight());
transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
代码示例来源:origin: geotools/geotools
/** Apply scaling parameter to the ROI to return the scaled version */
private ROI computeScaledROI(double[] scalingParams) throws NoninvertibleTransformException {
ROI newRoi = null;
if (roi != null) {
AffineTransform sTx =
AffineTransform.getScaleInstance(scalingParams[0], scalingParams[1]);
sTx.concatenate(
AffineTransform.getTranslateInstance(scalingParams[2], scalingParams[3]));
newRoi = roi.transform(sTx.createInverse());
}
return newRoi;
}
代码示例来源:origin: vsch/flexmark-java
public static BufferedImage scaleImage(BufferedImage sourceImage, int newWidth, int newHeight, int opType) {
if (sourceImage == null) {
return null;
}
if (newWidth == 0 || newHeight == 0) {
return null;
}
AffineTransform at = AffineTransform.getScaleInstance(
(double) newWidth / sourceImage.getWidth(null),
(double) newHeight / sourceImage.getHeight(null)
);
// http://nickyguides.digital-digest.com/bilinear-vs-bicubic.htm
AffineTransformOp op = new AffineTransformOp(at, opType != 0 ? opType : AffineTransformOp.TYPE_BILINEAR);
return op.filter(sourceImage, null);
}
代码示例来源:origin: apache/pdfbox
public Rectangle2D getBounds()
{
Point2D size = new Point2D.Double(pageSize.getWidth(), pageSize.getHeight());
// apply the underlying Graphics2D device's DPI transform and y-axis flip
Matrix m = new Matrix(xform);
AffineTransform dpiTransform = AffineTransform.getScaleInstance(Math.abs(m.getScalingFactorX()), Math.abs(m.getScalingFactorY()));
size = dpiTransform.transform(size, size);
// Flip y
return new Rectangle2D.Double(minX - pageSize.getLowerLeftX() * Math.abs(m.getScalingFactorX()),
size.getY() - minY - height + pageSize.getLowerLeftY() * Math.abs(m.getScalingFactorY()),
width, height);
}
}
代码示例来源:origin: geotools/geotools
@Test
public void testBounds() {
GeneralPath gp = new GeneralPath();
gp.moveTo(0f, 0f);
gp.lineTo(1, 0.3);
gp.lineTo(0f, 0.6f);
gp.closePath();
AffineTransform at = AffineTransform.getScaleInstance(1.5, 1.5);
TransformedShape ts = new TransformedShape(gp, at);
assertEquals(new Rectangle(0, 0, 2, 1), ts.getBounds());
}
}
代码示例来源:origin: geotools/geotools
public void testOGCScaleAffineProjected() throws Exception {
// 1 pixel == 500 m => 0.00028 m [ screen] == 500 m [world]
// => scaleDenominator = 500/0.00028
final AffineTransform screenToWord = AffineTransform.getScaleInstance(500, 500);
final AffineTransform worldToScreen = screenToWord.createInverse();
final CoordinateReferenceSystem crs = DefaultEngineeringCRS.CARTESIAN_2D;
double scale;
scale = RendererUtilities.calculateOGCScaleAffine(crs, worldToScreen, new HashMap());
assertEquals(500 / 0.00028, scale, 0.0001);
worldToScreen.rotate(1.0);
scale = RendererUtilities.calculateOGCScaleAffine(crs, worldToScreen, new HashMap());
assertEquals(500 / 0.00028, scale, 0.0001);
worldToScreen.translate(100.0, 100.0);
scale = RendererUtilities.calculateOGCScaleAffine(crs, worldToScreen, new HashMap());
assertEquals(500 / 0.00028, scale, 0.0001);
}
代码示例来源:origin: geotools/geotools
/**
* Test the pass through transform using an affine transform. The "passthrough" of such
* transform are optimized in a special way.
*/
@Test
public void testLinear() throws FactoryException, TransformException {
runTest(
mtFactory.createAffineTransform(
new GeneralMatrix(AffineTransform.getScaleInstance(4, 2))));
}
内容来源于网络,如有侵权,请联系作者删除!