From 3f5ae7b69899e36e386eeb45cb323d14cb69eb89 Mon Sep 17 00:00:00 2001 From: "Leo.Qin" Date: Thu, 22 May 2025 11:35:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-152615=20=E6=A8=A1=E6=9D=BF=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E7=AE=A1=E7=90=86-=E6=8E=A7=E4=BB=B6=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F-=E5=9B=BE=E6=A0=87=E9=A2=9C=E8=89=B2=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=BB=91=E8=89=B2=E6=88=96=E7=99=BD=E8=89=B2=E5=90=8E?= =?UTF-8?q?=20=E5=86=8D=E9=80=89=E6=8B=A9=E5=85=B6=E4=BB=96=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E4=B8=8D=E4=BC=9A=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/widgettheme/theme/panel/ImageUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ImageUtils.java b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ImageUtils.java index 63da90e6f7..1ef7275e46 100644 --- a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ImageUtils.java +++ b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ImageUtils.java @@ -46,7 +46,7 @@ public class ImageUtils { * @param color 颜色 */ private static void setRedPixels(int[] pixels, Color color) { - pixels[0] = pixels[0] > 0 && pixels[0] < 255 ? color.getRed() : 255; + pixels[0] = pixels[0] >= 0 && pixels[0] <= 255 ? color.getRed() : 255; } /** @@ -56,7 +56,7 @@ public class ImageUtils { * @param color 颜色 */ private static void setGreenPixels(int[] pixels, Color color) { - pixels[1] = pixels[1] > 0 && pixels[1] < 255 ? color.getGreen() : 255; + pixels[1] = pixels[1] >= 0 && pixels[1] <= 255 ? color.getGreen() : 255; } /** @@ -66,7 +66,7 @@ public class ImageUtils { * @param color 颜色 */ private static void setBluePixels(int[] pixels, Color color) { - pixels[2] = pixels[2] > 0 && pixels[2] < 255 ? color.getBlue() : 255; + pixels[2] = pixels[2] >= 0 && pixels[2] <= 255 ? color.getBlue() : 255; } /** From 26db8ec2bf63dc747b6f12f775c22ca061a22437 Mon Sep 17 00:00:00 2001 From: "Leo.Qin" Date: Thu, 22 May 2025 19:04:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-152615=20=E6=B7=BB=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theme/panel/ImageUtilsTest.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 designer-base/src/test/java/com/fr/widgettheme/theme/panel/ImageUtilsTest.java diff --git a/designer-base/src/test/java/com/fr/widgettheme/theme/panel/ImageUtilsTest.java b/designer-base/src/test/java/com/fr/widgettheme/theme/panel/ImageUtilsTest.java new file mode 100644 index 0000000000..a1d2c875a4 --- /dev/null +++ b/designer-base/src/test/java/com/fr/widgettheme/theme/panel/ImageUtilsTest.java @@ -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]); + } +} \ No newline at end of file