From af009c3c7866e6b4ecbf8027cd63d167630d996c Mon Sep 17 00:00:00 2001 From: plough Date: Mon, 26 Dec 2016 11:25:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=E3=80=82?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/style/color/ColorPicker.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/designer_base/src/com/fr/design/style/color/ColorPicker.java b/designer_base/src/com/fr/design/style/color/ColorPicker.java index 1fa7fb03f..cb30c186d 100644 --- a/designer_base/src/com/fr/design/style/color/ColorPicker.java +++ b/designer_base/src/com/fr/design/style/color/ColorPicker.java @@ -26,6 +26,7 @@ public class ColorPicker extends JDialog implements ActionListener private Timer timer; // 用于定时重绘 private int FPS = 45; // 重绘取色器的频率 + private int timeCycle = 1000 / FPS; // 时钟周期 private ColorSelectable colorSelectable; private Point mousePos; // 鼠标的绝对坐标 @@ -33,6 +34,7 @@ public class ColorPicker extends JDialog implements ActionListener private Boolean setColorRealTime; // 实时设定颜色值 + /** * 构造函数,创建一个取色框窗体 */ @@ -53,7 +55,6 @@ public class ColorPicker extends JDialog implements ActionListener } public void start() { - int timeCycle = 1000 / FPS; timer = new Timer(timeCycle, this); timer.start(); hideCursor(); @@ -125,6 +126,12 @@ class ColorPickerPanel extends JPanel private int scaleFactor; // 放大倍数 private Robot robot; + // getPixelColor 常数 + private static int SHIFT_STEP = 8; // 比特位右移步长 + private static int AND_R = 0xff0000; + private static int AND_G = 0xff00; + private static int AND_B = 0xff; + /** * 带参数的构造函数 * @param scaleFactor 放大倍数 @@ -160,10 +167,9 @@ class ColorPickerPanel extends JPanel public Color getPixelColor(Point mousePos) { int rgb = screenImage.getRGB(mousePos.x, mousePos.y); - int shiftStep = 8; // 右移的比特位 - int R = (rgb & 0xff0000) >> shiftStep * 2; - int G = (rgb & 0xff00) >> shiftStep; - int B = (rgb & 0xff); + int R = (rgb & AND_R) >> SHIFT_STEP * 2; + int G = (rgb & AND_G) >> SHIFT_STEP; + int B = (rgb & AND_B); return new Color(R, G, B); }