本文整理汇总了Java中org.imgscalr.Scalr.Mode.FIT_TO_WIDTH属性的典型用法代码示例。如果您正苦于以下问题:Java Mode.FIT_TO_WIDTH属性的具体用法?Java Mode.FIT_TO_WIDTH怎么用?Java Mode.FIT_TO_WIDTH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.imgscalr.Scalr.Mode
的用法示例。
在下文中一共展示了Mode.FIT_TO_WIDTH属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBestFit
private BufferedImage getBestFit (BufferedImage bi, int maxWidth, int maxHeight)
{
if (bi == null)
return null ;
Mode mode = Mode.AUTOMATIC ;
int maxSize = Math.min(maxWidth, maxHeight) ;
double dh = (double)bi.getHeight() ;
if (dh > Double.MIN_VALUE)
{
double imageAspectRatio = (double)bi.getWidth() / dh ;
if (maxHeight * imageAspectRatio <= maxWidth)
{
maxSize = maxHeight ;
mode = Mode.FIT_TO_HEIGHT ;
}
else
{
maxSize = maxWidth ;
mode = Mode.FIT_TO_WIDTH ;
}
}
return Scalr.resize(bi, Method.QUALITY, mode, maxSize, Scalr.OP_ANTIALIAS) ;
}
示例2: scaleImage
private BufferedImage scaleImage(BufferedImage image, int frameWidth, int frameHeight) throws IOException {
int targetSize = 0;
Mode mode;
if (props.getScreenshotViewScaling() == ViewScaling.HORIZONTAL) {
targetSize = (int) (frameWidth * 0.97);
mode = Mode.FIT_TO_WIDTH;
} else {
targetSize = frameHeight - 160;
mode = Mode.FIT_TO_HEIGHT;
}
if (mode == Mode.FIT_TO_WIDTH && image.getWidth() <= targetSize) {
return image;
} else if (mode == Mode.FIT_TO_HEIGHT && image.getHeight() <= targetSize) {
return image;
} else {
BufferedImage scaledImage = Scalr.resize(image, mode, targetSize, Scalr.OP_ANTIALIAS);
return scaledImage;
}
}
示例3: paintComponent
/**
* {@inheritDoc}.
*/
@Override
protected synchronized void paintComponent(Graphics g) {
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, getWidth(), getHeight());
if (image != null)
{
Mode mode = Mode.AUTOMATIC ;
int maxSize = Math.min(this.getWidth(), this.getHeight()) ;
double dh = (double)image.getHeight() ;
if (dh > Double.MIN_VALUE)
{
double imageAspectRatio = (double)image.getWidth() / dh ;
if (this.getHeight() * imageAspectRatio <= this.getWidth())
{
maxSize = this.getHeight() ;
mode = Mode.FIT_TO_HEIGHT ;
}
else
{
maxSize = this.getWidth() ;
mode = Mode.FIT_TO_WIDTH ;
}
}
BufferedImage scaledImg = Scalr.resize(image, Method.AUTOMATIC, mode, maxSize, Scalr.OP_ANTIALIAS) ;
g.drawImage(scaledImg, 0, 0, scaledImg.getWidth(), scaledImg.getHeight(), this);
}
}
示例4: fitTo
static public BufferedImage fitTo(BufferedImage source, int width, int height) {
Mode mode;
if (source.getHeight() > source.getWidth()) {
mode = Mode.FIT_TO_HEIGHT;
} else {
mode = Mode.FIT_TO_WIDTH;
}
return Scalr.resize(source, Method.QUALITY, mode, width, height);
}