mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
fix code
This commit is contained in:
parent
0bdeb7a17b
commit
4c5e127c88
@ -613,13 +613,8 @@ public class Img implements Serializable {
|
||||
|
||||
// 目标图像
|
||||
final BufferedImage targetImg = new BufferedImage(rectangle.width, rectangle.height, getTypeInt());
|
||||
final Graphics2D graphics2d = targetImg.createGraphics();
|
||||
|
||||
// 填充背景色
|
||||
if(null != this.backgroundColor){
|
||||
graphics2d.setColor(this.backgroundColor);
|
||||
graphics2d.fill(rectangle);
|
||||
}
|
||||
// 创建画笔并填充背景色
|
||||
final Graphics2D graphics2d = GraphicsUtil.createGraphics(targetImg, this.backgroundColor);
|
||||
|
||||
graphics2d.setRenderingHints(
|
||||
RenderingHintsBuilder.of()
|
||||
|
@ -456,7 +456,7 @@ public class ImgUtil {
|
||||
if (false == destDir.exists()) {
|
||||
FileUtil.mkdir(destDir);
|
||||
} else if (false == destDir.isDirectory()) {
|
||||
throw new IllegalArgumentException("Destination Dir must be a Directory !");
|
||||
throw new IllegalArgumentException("Destination must be a Directory !");
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.swing.img;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.builder.Builder;
|
||||
|
||||
import java.awt.RenderingHints;
|
||||
@ -7,7 +8,19 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 着色微调构建器
|
||||
* 定义和管理键和关联值的集合构建器,提供配置包括:
|
||||
* <ol>
|
||||
* <li>{@link RenderingHints#KEY_ANTIALIASING} 抗锯齿 </li>
|
||||
* <li>{@link RenderingHints#KEY_TEXT_ANTIALIASING} 文本抗锯齿</li>
|
||||
* <li>{@link RenderingHints#KEY_COLOR_RENDERING} 颜色着色的渲染方式</li>
|
||||
* <li>{@link RenderingHints#KEY_DITHERING} 抖动</li>
|
||||
* <li>{@link RenderingHints#KEY_FRACTIONALMETRICS} 字体规格</li>
|
||||
* <li>{@link RenderingHints#KEY_INTERPOLATION} 内插</li>
|
||||
* <li>{@link RenderingHints#KEY_ALPHA_INTERPOLATION} alpha合成微调</li>
|
||||
* <li>{@link RenderingHints#KEY_RENDERING} 着色</li>
|
||||
* <li>{@link RenderingHints#KEY_STROKE_CONTROL} 笔划规范化控制</li>
|
||||
* <li>{@link RenderingHints#KEY_TEXT_LCD_CONTRAST} LCD文本对比呈现</li>
|
||||
* </ol>
|
||||
*
|
||||
* @author looly
|
||||
* @since 6.0.0
|
||||
@ -50,6 +63,22 @@ public class RenderingHintsBuilder implements Builder<RenderingHints> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对文本着色时是否抗锯齿
|
||||
*
|
||||
* @param textAntialias 文本抗锯齿方式,{@code null}表示移除此选项
|
||||
* @return this
|
||||
*/
|
||||
public RenderingHintsBuilder setTextAntialias(final TextAntialias textAntialias) {
|
||||
final RenderingHints.Key key = RenderingHints.KEY_TEXT_ANTIALIASING;
|
||||
if (null == textAntialias) {
|
||||
this.hintsMap.remove(key);
|
||||
} else {
|
||||
this.hintsMap.put(key, textAntialias.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置控制颜色着色的渲染方式
|
||||
*
|
||||
@ -117,38 +146,6 @@ public class RenderingHintsBuilder implements Builder<RenderingHints> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置着色技术,在速度和质量之间进行权衡。
|
||||
*
|
||||
* @param render 着色技术,{@code null}表示移除此选项
|
||||
* @return this
|
||||
*/
|
||||
public RenderingHintsBuilder setRendering(final Render render) {
|
||||
final RenderingHints.Key key = RenderingHints.KEY_RENDERING;
|
||||
if (null == render) {
|
||||
this.hintsMap.remove(key);
|
||||
} else {
|
||||
this.hintsMap.put(key, render.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对文本着色时是否抗锯齿
|
||||
*
|
||||
* @param textAntialias 文本抗锯齿方式,{@code null}表示移除此选项
|
||||
* @return this
|
||||
*/
|
||||
public RenderingHintsBuilder setTextAntialias(final TextAntialias textAntialias) {
|
||||
final RenderingHints.Key key = RenderingHints.KEY_TEXT_ANTIALIASING;
|
||||
if (null == textAntialias) {
|
||||
this.hintsMap.remove(key);
|
||||
} else {
|
||||
this.hintsMap.put(key, textAntialias.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置alpha合成微调
|
||||
*
|
||||
@ -166,18 +163,17 @@ public class RenderingHintsBuilder implements Builder<RenderingHints> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置LCD文本对比呈现<br>
|
||||
* ,100 到 250 之间的正整数。通常,有用值的范围缩小到 140-180
|
||||
* 设置着色技术,在速度和质量之间进行权衡。
|
||||
*
|
||||
* @param textLCDContrast LCD文本对比呈现,100 到 250 之间的正整数
|
||||
* @param render 着色技术,{@code null}表示移除此选项
|
||||
* @return this
|
||||
*/
|
||||
public RenderingHintsBuilder setAlphaInterpolation(final Integer textLCDContrast) {
|
||||
final RenderingHints.Key key = RenderingHints.KEY_TEXT_LCD_CONTRAST;
|
||||
if (null == textLCDContrast) {
|
||||
public RenderingHintsBuilder setRendering(final Render render) {
|
||||
final RenderingHints.Key key = RenderingHints.KEY_RENDERING;
|
||||
if (null == render) {
|
||||
this.hintsMap.remove(key);
|
||||
} else {
|
||||
this.hintsMap.put(key, textLCDContrast);
|
||||
this.hintsMap.put(key, render.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -188,7 +184,7 @@ public class RenderingHintsBuilder implements Builder<RenderingHints> {
|
||||
* @param strokeControl 笔划规范化控制,{@code null}表示移除此选项
|
||||
* @return this
|
||||
*/
|
||||
public RenderingHintsBuilder setAlphaInterpolation(final StrokeControl strokeControl) {
|
||||
public RenderingHintsBuilder setStrokeControl(final StrokeControl strokeControl) {
|
||||
final RenderingHints.Key key = RenderingHints.KEY_STROKE_CONTROL;
|
||||
if (null == strokeControl) {
|
||||
this.hintsMap.remove(key);
|
||||
@ -198,6 +194,23 @@ public class RenderingHintsBuilder implements Builder<RenderingHints> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置LCD文本对比呈现<br>
|
||||
* ,100 到 250 之间的正整数。通常,有用值的范围缩小到 140-180
|
||||
*
|
||||
* @param textLCDContrast LCD文本对比呈现,100 到 250 之间的正整数
|
||||
* @return this
|
||||
*/
|
||||
public RenderingHintsBuilder setTextLCDContrast(final Integer textLCDContrast) {
|
||||
final RenderingHints.Key key = RenderingHints.KEY_TEXT_LCD_CONTRAST;
|
||||
if (null == textLCDContrast) {
|
||||
this.hintsMap.remove(key);
|
||||
} else {
|
||||
this.hintsMap.put(key, Assert.checkBetween(textLCDContrast.intValue(), 100, 250));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderingHints build() {
|
||||
return new RenderingHints(this.hintsMap);
|
||||
|
Loading…
Reference in New Issue
Block a user