Browse Source
Merge in DESIGN/design from ~LEO.QIN/design:release/11.0 to release/11.0 * commit '26db8ec2bf63dc747b6f12f775c22ca061a22437': REPORT-152615 添加单测 REPORT-152615 模板主题管理-控件样式-图标颜色选择黑色或白色后 再选择其他颜色不会渲染release/11.0
2 changed files with 96 additions and 3 deletions
@ -0,0 +1,93 @@
|
||||
package com.fr.widgettheme.theme.panel; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import javax.swing.ImageIcon; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.image.BufferedImage; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertNotNull; |
||||
|
||||
|
||||
/** |
||||
* @author Leo.Qin |
||||
* @since 11.0 |
||||
* Created on 2025/5/22 |
||||
*/ |
||||
public class ImageUtilsTest { |
||||
|
||||
@Test |
||||
public void testColorImage() { |
||||
// 创建一个测试用的BufferedImage
|
||||
BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB); |
||||
Color testColor = new Color(123, 45, 67); |
||||
|
||||
// 执行测试方法
|
||||
BufferedImage result = ImageUtils.colorImage(image, testColor); |
||||
|
||||
// 验证结果
|
||||
assertNotNull(result); |
||||
assertEquals(10, result.getWidth()); |
||||
assertEquals(10, result.getHeight()); |
||||
|
||||
// 检查图像中的像素颜色是否符合预期
|
||||
int[] pixel = new int[4]; |
||||
result.getRaster().getPixel(5, 5, pixel); |
||||
assertEquals(testColor.getRed(), pixel[0]); |
||||
assertEquals(testColor.getGreen(), pixel[1]); |
||||
assertEquals(testColor.getBlue(), pixel[2]); |
||||
} |
||||
|
||||
@Test |
||||
public void testImageIconToBufferedImage() { |
||||
// 创建一个简单的测试ImageIcon
|
||||
BufferedImage srcImage = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB); |
||||
ImageIcon icon = new ImageIcon(srcImage); |
||||
|
||||
// 执行测试方法
|
||||
BufferedImage result = ImageUtils.imageIconToBufferedImage(icon); |
||||
|
||||
// 验证结果
|
||||
assertNotNull(result); |
||||
assertEquals(icon.getIconWidth(), result.getWidth()); |
||||
assertEquals(icon.getIconHeight(), result.getHeight()); |
||||
assertEquals(BufferedImage.TYPE_INT_ARGB, result.getType()); |
||||
} |
||||
|
||||
@Test |
||||
public void testPixelProcessing() { |
||||
// 测试边界情况下的像素处理
|
||||
BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB); |
||||
Graphics2D g2d = image.createGraphics(); |
||||
|
||||
// 设置像素值为边界值
|
||||
g2d.setColor(new Color(0, 0, 0, 255)); |
||||
g2d.fillRect(0, 0, 1, 1); |
||||
|
||||
g2d.setColor(new Color(255, 255, 255, 255)); |
||||
g2d.fillRect(1, 1, 1, 1); |
||||
|
||||
g2d.dispose(); |
||||
|
||||
// 使用自定义颜色处理图像
|
||||
Color customColor = new Color(100, 150, 200); |
||||
BufferedImage result = ImageUtils.colorImage(image, customColor); |
||||
|
||||
// 验证处理后的像素值
|
||||
int[] pixel1 = new int[4]; |
||||
int[] pixel2 = new int[4]; |
||||
result.getRaster().getPixel(0, 0, pixel1); |
||||
result.getRaster().getPixel(1, 1, pixel2); |
||||
|
||||
// 两个像素点应该都被处理成自定义颜色
|
||||
assertEquals(customColor.getRed(), pixel1[0]); |
||||
assertEquals(customColor.getGreen(), pixel1[1]); |
||||
assertEquals(customColor.getBlue(), pixel1[2]); |
||||
|
||||
assertEquals(customColor.getRed(), pixel2[0]); |
||||
assertEquals(customColor.getGreen(), pixel2[1]); |
||||
assertEquals(customColor.getBlue(), pixel2[2]); |
||||
} |
||||
} |
Loading…
Reference in new issue