├── README.md ├── color.java ├── color2.java ├── headPicture.zip ├── picturingAI.jar └── save ├── Universe.png ├── data ├── 0.jpg ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg └── 6.jpg ├── last.jpg └── yileina.jpg /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | 使用Java实现的一个图片处理软件 4 | 5 | 基础功能:基础功能如调整饱和度、亮度、像素化等 6 | 新功能:实现图像油画风格、厚涂风格等的转换 7 | 8 | 9 | 10 | ## 部分功能预览 11 | 12 | #### 原图 13 | 14 | ![yileina](./save/yileina.jpg) 15 | 16 | #### 一键处理后的效果图 17 | 18 | 风格简化: 19 | 20 | ![yileina](./save/data/0.jpg) 21 | 22 | ## 关于 23 | 24 | 当前不支持更改分辨率,在分辨率少于1080*800的电脑上运行UI可能会溢出屏幕。 25 | 26 | **视频对应源代码请下载color2.java;安装java环境之后可以直接下载.jar文件运行。** 27 | 28 | -------------------------------------------------------------------------------- /color.java: -------------------------------------------------------------------------------- 1 | 2 | import java.awt.*; 3 | import java.awt.image.BufferedImage; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.util.Dictionary; 8 | import java.util.Hashtable; 9 | 10 | import javax.imageio.ImageIO; 11 | import javax.swing.*; 12 | import javax.swing.event.ChangeEvent; 13 | import javax.swing.event.ChangeListener; 14 | import javax.swing.filechooser.FileNameExtensionFilter; 15 | 16 | /** 17 | * 18 | 19 | * 20 | * 21 | * 22 | * 23 | * 2020/12/10 24 | * 25 | * */ 26 | 27 | public class color extends JFrame { 28 | String url = ""; 29 | int time = 0; 30 | int times = 1; 31 | double fillFrame = 1; 32 | int pixelValue = 1; 33 | int colorMin = 10, colorMax = 50; 34 | private JPanel panel = null; 35 | private JPanel panel1 = null; 36 | private JSlider slider = null; 37 | private BufferedImage img = null; 38 | private BufferedImage img1 = null; 39 | private BufferedImage img2 = null; 40 | private BufferedImage imgLast = null; 41 | 42 | JLabel lab1 = new JLabel(""); 43 | JLabel lab2 = new JLabel(""); 44 | JTextArea r1 = new JTextArea(); 45 | JTextArea g1 = new JTextArea(); 46 | JTextArea b1 = new JTextArea(); 47 | JTextArea r2 = new JTextArea(); 48 | JTextArea g2 = new JTextArea(); 49 | JTextArea b2 = new JTextArea(); 50 | JTextArea rg1 = new JTextArea(); 51 | JTextArea gb1 = new JTextArea(); 52 | JTextArea rg2 = new JTextArea(); 53 | JTextArea gb2 = new JTextArea(); 54 | JColorChooser op = new JColorChooser(Color.black); 55 | 56 | JTextArea num1 = new JTextArea(); 57 | JTextArea num2 = new JTextArea(); 58 | JTextArea num3 = new JTextArea(); 59 | JTextArea num4 = new JTextArea(); 60 | JTextArea num5 = new JTextArea(); 61 | JTextArea num6 = new JTextArea(); 62 | JTextArea num7 = new JTextArea(); 63 | JTextArea num9 = new JTextArea(); 64 | JTextArea num10 = new JTextArea(); 65 | JTextArea num11 = new JTextArea(); 66 | JTextArea num12 = new JTextArea(); 67 | JTextArea num13 = new JTextArea(); 68 | JTextArea num14 = new JTextArea(); 69 | JTextArea numMin = new JTextArea(); 70 | JTextArea numMax = new JTextArea(); 71 | JTextArea value1 = new JTextArea(); 72 | JRadioButton auto1, auto2, removeBlackWhite, removeBilibili, onlyBlackAndWhite, blackFirst, removeForeground, twoDimensionCode, lightsPoly2D, similar, contract, colorLimit, colorChange; 73 | private double value = 0; 74 | JButton Cal = new JButton("生成"); 75 | JButton Cal1 = new JButton("预览"); 76 | JButton load = new JButton("读取图片"); 77 | JButton change = new JButton("转换图片"); 78 | 79 | JComboBox Tb = new JComboBox(new String[]{"左上", "最近的", "不消除"}); 80 | JComboBox edgeTestMethod = new JComboBox(new String[]{"1.仅最近的", "2.根据旁边8格的", "1的反转", "2的反转"}); 81 | JComboBox ColorChoose = new JComboBox(new String[]{"限制到一半颜色", "限制到1/3颜色", "限制到1/5颜色", "限制到1/7颜色", "限制到1/10颜色"}); 82 | JComboBox ColorChoose1 = new JComboBox(new String[]{"剔除相似大于100的颜色", "剔除相似大于50的颜色", "剔除相似大于30的颜色", "剔除相似大于20的颜色", "剔除相似大于10的颜色"}); 83 | 84 | final JTabbedPane tabbedPane = new JTabbedPane(); 85 | 86 | 87 | private double[] CalculateTotal = {0, 0, 0}; 88 | private int width, height; 89 | private double r, g, b; 90 | private boolean stop = false; 91 | int numOfPoly2D = 30; 92 | int smooth = 0; 93 | 94 | 95 | public color() { 96 | initComponent(); 97 | this.setVisible(true); 98 | } 99 | 100 | 101 | private void clickTry() { 102 | 103 | begin(true); 104 | 105 | } 106 | 107 | private void click() { 108 | begin(false); 109 | } 110 | 111 | private void begin(boolean try1) { 112 | int n1 = 0, n2 = 0, n3 = 0, n4 = 1, n5 = 0, n6 = 0, n7 = 0, n8 = 0, n9 = 0, n10 = 1, n11 = 1; 113 | try { 114 | smooth = Integer.parseInt(num12.getText()); 115 | } catch (Exception e) { 116 | } 117 | try { 118 | colorMin = Integer.parseInt(numMin.getText()); 119 | } catch (Exception e) { 120 | } 121 | try { 122 | colorMax = Integer.parseInt(numMax.getText()); 123 | } catch (Exception e) { 124 | } 125 | try { 126 | n1 = Integer.parseInt(num1.getText()); 127 | } catch (Exception e) { 128 | } 129 | try { 130 | n2 = Integer.parseInt(num2.getText()); 131 | } catch (Exception e) { 132 | } 133 | try { 134 | n3 = Integer.parseInt(num3.getText()); 135 | } catch (Exception e) { 136 | } 137 | try { 138 | n4 = Integer.parseInt(num4.getText()); 139 | } catch (Exception e) { 140 | } 141 | try { 142 | n5 = Integer.parseInt(num5.getText()); 143 | } catch (Exception e) { 144 | } 145 | try { 146 | n6 = Integer.parseInt(num6.getText()); 147 | } catch (Exception e) { 148 | } 149 | try { 150 | n8 = Tb.getSelectedIndex(); 151 | } catch (Exception e) { 152 | } 153 | try { 154 | n7 = Integer.parseInt(num7.getText()); 155 | } catch (Exception e) { 156 | } 157 | try { 158 | n9 = Integer.parseInt(num9.getText()); 159 | } catch (Exception e) { 160 | } 161 | try { 162 | n10 = Integer.parseInt(num10.getText()); 163 | } catch (Exception e) { 164 | } 165 | try { 166 | n11 = Integer.parseInt(num11.getText()); 167 | } catch (Exception e) { 168 | } 169 | try { 170 | pixelValue = Integer.parseInt(num14.getText()); 171 | if (fillFrame < 1) fillFrame = 1; 172 | } catch (Exception e) { 173 | } 174 | try { 175 | fillFrame = Double.parseDouble(num13.getText()); 176 | if (fillFrame < 1) fillFrame = 1; 177 | } catch (Exception e) { 178 | } 179 | if (auto1.isSelected()) { 180 | n1 = -1; 181 | } 182 | if (auto2.isSelected()) { 183 | n7 = -1; 184 | } 185 | 186 | if (try1) { 187 | processImg(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11); 188 | } else { 189 | for (times = 1; times < 10000; times++) { 190 | if (time < (int) (times / fillFrame + 1)) { 191 | time = (int) (times / fillFrame + 1); 192 | initImg(new File(url + time + ").jpg")); 193 | } 194 | processImg(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11); 195 | if (stop) break; 196 | } 197 | } 198 | 199 | } 200 | 201 | private void Load() { 202 | String path = System.getProperty("user.dir"); 203 | JFileChooser choose = new JFileChooser(path); 204 | choose.setDialogTitle("Please Choose Picture"); 205 | FileNameExtensionFilter filter = new FileNameExtensionFilter( 206 | "picture", "jpg"); 207 | choose.setFileFilter(filter); 208 | int returnVal = choose.showOpenDialog(null); 209 | if (returnVal == JFileChooser.APPROVE_OPTION) { 210 | String filepath = choose.getSelectedFile().getPath(); 211 | initImg(new File(filepath)); 212 | url = filepath.substring(0, filepath.lastIndexOf("(") + 1); 213 | 214 | try { 215 | times = Integer.parseInt(filepath.substring(filepath.lastIndexOf("(") + 1, filepath.lastIndexOf(")"))); 216 | } catch (Exception e) { 217 | } 218 | System.out.println(url); 219 | System.out.println(times); 220 | panel1.repaint(); 221 | } 222 | } 223 | 224 | private void initComponent() { 225 | 226 | lab1.setBounds(380, 60, 300, 70); 227 | lab1.setFont(new Font("", Font.BOLD, 15)); 228 | lab2.setBounds(380, 260, 300, 70); 229 | lab2.setFont(new Font("", Font.BOLD, 15)); 230 | 231 | this.setTitle("生成奇奇怪怪的图片吧 by 零殇"); 232 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 233 | this.setSize(1640, 1000); 234 | setLayout(null); 235 | 236 | auto1 = new JRadioButton("使用自动生成的数据", false); 237 | auto1.setBounds(112, 60, 200, 60); 238 | auto2 = new JRadioButton("使用自动生成的数据", false); 239 | auto2.setBounds(112, 260, 200, 60); 240 | removeBlackWhite = new JRadioButton("移除灰色斑", false); 241 | removeBlackWhite.setBounds(52, 500, 360, 40); 242 | removeBilibili = new JRadioButton("移除右上角'Bilibili'", false); 243 | removeBilibili.setBounds(52, 460, 260, 40); 244 | onlyBlackAndWhite = new JRadioButton("使图片以黑白展示", false); 245 | onlyBlackAndWhite.setBounds(82, 480, 330, 40); 246 | blackFirst = new JRadioButton("暗色边缘优先去除", false); 247 | blackFirst.setBounds(52, 405, 200, 40); 248 | removeForeground = new JRadioButton("移除前景色", false); 249 | removeForeground.setBounds(52, 530, 360, 40); 250 | similar = new JRadioButton("仅对近似色模糊", true); 251 | similar.setBounds(432, 510, 360, 40); 252 | twoDimensionCode = new JRadioButton("加入 n*79*79 二维码(仅黑白模式使用)", false); 253 | twoDimensionCode.setBounds(20, 20, 360, 40); 254 | 255 | contract = new JRadioButton("生成对比图", true); 256 | contract.setBounds(20, 350, 360, 40); 257 | 258 | colorLimit = new JRadioButton("限制图片颜色数量", false); 259 | colorLimit.setBounds(320, 20, 360, 40); 260 | 261 | lightsPoly2D = new JRadioButton("光的波粒二象性(仅非黑白模式使用) 每一帧移动速度(-100~100)", false); 262 | lightsPoly2D.setBounds(20, 80, 430, 40); 263 | 264 | JLabel fill = new JLabel(" 补帧率(预期帧数/原本帧数)(可输入小数)"); 265 | fill.setBounds(20, 180, 630, 40); 266 | fill.setFont(new Font("", Font.BOLD, 20)); 267 | 268 | JLabel pixel = new JLabel(" 像素化图片(n*n格合并为一格)(1-10)"); 269 | pixel.setBounds(20, 280, 630, 40); 270 | pixel.setFont(new Font("", Font.BOLD, 20)); 271 | 272 | 273 | JPanel panel4th = new JPanel(); 274 | panel4th.setBounds(0, 0, 600, 600); 275 | panel4th.setLayout(null); 276 | panel4th.add(twoDimensionCode); 277 | panel4th.add(contract); 278 | panel4th.add(lightsPoly2D); 279 | 280 | JPanel panel3rd = new JPanel(); 281 | panel3rd.setBounds(0, 0, 600, 600); 282 | panel3rd.setLayout(null); 283 | 284 | JPanel panel1st = new JPanel(); 285 | panel1st.setBounds(0, 0, 600, 600); 286 | panel1st.setLayout(null); 287 | panel1st.add(auto1); 288 | panel1st.add(auto2); 289 | panel1st.add(colorLimit); 290 | panel1st.add(removeBilibili); 291 | panel1st.add(removeBlackWhite); 292 | panel1st.add(lab1); 293 | panel1st.add(lab2); 294 | panel1st.add(blackFirst); 295 | panel1st.add(removeForeground); 296 | panel1st.add(similar); 297 | 298 | 299 | JPanel panel2nd = new JPanel(); 300 | panel2nd.setBounds(0, 0, 600, 600); 301 | panel2nd.setLayout(null); 302 | panel2nd.add(onlyBlackAndWhite); 303 | 304 | tabbedPane.addTab("边缘", null, panel1st, ""); 305 | tabbedPane.addTab("基础", null, panel2nd, ""); 306 | tabbedPane.addTab("色彩提取器", null, panel3rd, ""); 307 | tabbedPane.addTab("其他", null, panel4th, ""); 308 | tabbedPane.setBounds(1000, 200, 600, 600); 309 | 310 | 311 | JLabel rgb1 = new JLabel(" (R-G)范围 (G-B)范围"); 312 | rgb1.setBounds(400, 10, 200, 50); 313 | rg1.setText("0"); 314 | rg1.setBounds(400, 50, 70, 50); 315 | rg1.setFont(new Font("", Font.BOLD, 40)); 316 | rg1.setForeground(Color.RED); 317 | rg2.setText("0"); 318 | rg2.setBounds(400, 120, 70, 50); 319 | rg2.setFont(new Font("", Font.BOLD, 40)); 320 | rg2.setForeground(Color.GREEN); 321 | gb1.setText("0"); 322 | gb1.setBounds(500, 50, 70, 50); 323 | gb1.setFont(new Font("", Font.BOLD, 40)); 324 | gb1.setForeground(Color.GREEN); 325 | gb2.setText("0"); 326 | gb2.setBounds(500, 120, 70, 50); 327 | gb2.setFont(new Font("", Font.BOLD, 40)); 328 | gb2.setForeground(Color.blue); 329 | 330 | r1.setText("0"); 331 | r1.setBounds(50, 50, 70, 50); 332 | r1.setFont(new Font("", Font.BOLD, 40)); 333 | r1.setForeground(Color.RED); 334 | r2.setText("0"); 335 | r2.setBounds(50, 120, 70, 50); 336 | r2.setFont(new Font("", Font.BOLD, 40)); 337 | r2.setForeground(Color.RED); 338 | g1.setText("0"); 339 | g1.setBounds(150, 50, 70, 50); 340 | g1.setFont(new Font("", Font.BOLD, 40)); 341 | g1.setForeground(Color.GREEN); 342 | g2.setText("0"); 343 | g2.setBounds(150, 120, 70, 50); 344 | g2.setFont(new Font("", Font.BOLD, 40)); 345 | g2.setForeground(Color.GREEN); 346 | b1.setText("0"); 347 | b1.setBounds(250, 50, 70, 50); 348 | b1.setFont(new Font("", Font.BOLD, 40)); 349 | b1.setForeground(Color.BLUE); 350 | b2.setText("0"); 351 | b2.setBounds(250, 120, 70, 50); 352 | b2.setFont(new Font("", Font.BOLD, 40)); 353 | b2.setForeground(Color.BLUE); 354 | colorChange = new JRadioButton("范围内颜色替换成调色板颜色(上面起始值,下面终值(颜色对应RGB)(0-255))", false); 355 | colorChange.setBounds(20, 180, 600, 40); 356 | op.setBounds(20, 250, 560, 310); 357 | panel3rd.add(op); 358 | panel3rd.add(r1); 359 | panel3rd.add(r2); 360 | panel3rd.add(g1); 361 | panel3rd.add(g2); 362 | panel3rd.add(b1); 363 | panel3rd.add(b2); 364 | panel3rd.add(gb1); 365 | panel3rd.add(gb2); 366 | panel3rd.add(rg1); 367 | panel3rd.add(rg2); 368 | panel3rd.add(rgb1); 369 | panel3rd.add(colorChange); 370 | 371 | Tb.setBounds(140, 360, 150, 40); 372 | Tb.setSelectedIndex(1); 373 | panel1st.add(Tb); 374 | 375 | ColorChoose.setBounds(340, 140, 150, 40); 376 | ColorChoose.setSelectedIndex(1); 377 | panel1st.add(ColorChoose); 378 | 379 | ColorChoose1.setBounds(340, 190, 150, 40); 380 | ColorChoose1.setSelectedIndex(0); 381 | panel1st.add(ColorChoose1); 382 | 383 | edgeTestMethod.setBounds(30, 160, 150, 40); 384 | edgeTestMethod.setSelectedIndex(0); 385 | panel1st.add(edgeTestMethod); 386 | 387 | panel1 = new JPanel() { 388 | @Override 389 | protected void paintComponent(Graphics g) { 390 | super.paintComponent(g); 391 | Graphics2D g2 = (Graphics2D) g; 392 | g2.drawImage(img1, 0, 0, this.getWidth(), this.getHeight(), null); 393 | } 394 | }; 395 | panel1.setBounds(80, 580, 580, 320); 396 | panel1.setBackground(new Color(224, 224, 255)); 397 | 398 | this.add(panel1); 399 | panel = new JPanel() { 400 | @Override 401 | protected void paintComponent(Graphics g) { 402 | super.paintComponent(g); 403 | Graphics2D g2 = (Graphics2D) g; 404 | g2.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null); 405 | } 406 | }; 407 | panel.setBounds(20, 20, 960, 540); 408 | panel.setBackground(new Color(224, 255, 224)); 409 | this.add(panel); 410 | 411 | load.setBounds(1100, 70, 120, 60); 412 | load.setFont(new Font("", Font.BOLD, 20)); 413 | load.addActionListener((e) -> Load()); 414 | change.setBounds(750, 650, 200, 60); 415 | change.setFont(new Font("", Font.BOLD, 20)); 416 | change.addActionListener((e) -> Change()); 417 | this.add(change); 418 | Cal.setBounds(1250, 70, 130, 60); 419 | Cal.setFont(new Font("", Font.BOLD, 20)); 420 | Cal.addActionListener((e) -> click()); 421 | Cal1.setBounds(1400, 70, 150, 60); 422 | Cal1.setFont(new Font("", Font.BOLD, 20)); 423 | Cal1.addActionListener((e) -> clickTry()); 424 | 425 | slider = new JSlider(); 426 | slider.setValue(1); 427 | slider.setPaintLabels(true); 428 | slider.setPaintTicks(true); 429 | slider.setMajorTickSpacing(100); 430 | slider.setMinorTickSpacing(5); 431 | Dictionary labels = new Hashtable(); 432 | for (int i = 0; i <= 100; i += 5) { 433 | labels.put(i, new JLabel("" + i)); 434 | } 435 | slider.setLabelTable(labels); 436 | slider.setBounds(0, 10, 1550, 40); 437 | slider.addChangeListener(new ChangeListener() { 438 | @Override 439 | public void stateChanged(ChangeEvent e) { 440 | if (slider.getValueIsAdjusting()) { 441 | int changeValue = slider.getValue(); 442 | num1.setText(String.valueOf(changeValue)); 443 | value = slider.getValue(); 444 | } 445 | } 446 | }); 447 | 448 | 449 | value1.setText(""); 450 | value1.setBounds(20, 10, 100, 40); 451 | value1.setFont(new Font("", Font.BOLD, 20)); 452 | value1.setForeground(Color.BLACK); 453 | 454 | 455 | num14.setText("1"); 456 | num14.setBounds(450, 270, 70, 50); 457 | num14.setFont(new Font("", Font.BOLD, 40)); 458 | num14.setForeground(Color.RED); 459 | 460 | num13.setText("1"); 461 | num13.setBounds(450, 170, 70, 50); 462 | num13.setFont(new Font("", Font.BOLD, 40)); 463 | num13.setForeground(Color.RED); 464 | 465 | num12.setText("0"); 466 | num12.setBounds(450, 460, 70, 50); 467 | num12.setFont(new Font("", Font.BOLD, 40)); 468 | num12.setForeground(Color.RED); 469 | 470 | 471 | num11.setText("1"); 472 | num11.setBounds(450, 70, 70, 50); 473 | num11.setFont(new Font("", Font.BOLD, 40)); 474 | num10.setText("3"); 475 | num10.setBounds(450, 360, 70, 50); 476 | num10.setFont(new Font("", Font.BOLD, 40)); 477 | num10.setForeground(Color.RED); 478 | num9.setText("0"); 479 | num9.setBounds(350, 360, 70, 50); 480 | num9.setFont(new Font("", Font.BOLD, 40)); 481 | num9.setForeground(Color.RED); 482 | 483 | num7.setText("0"); 484 | num7.setBounds(30, 260, 70, 50); 485 | num7.setFont(new Font("", Font.BOLD, 40)); 486 | num7.setForeground(Color.RED); 487 | num6.setText(""); 488 | num6.setBounds(230, 410, 70, 50); 489 | num6.setFont(new Font("", Font.BOLD, 40)); 490 | num6.setForeground(Color.RED); 491 | num5.setText(""); 492 | num5.setBounds(230, 310, 70, 50); 493 | num5.setFont(new Font("", Font.BOLD, 40)); 494 | num5.setForeground(Color.YELLOW); 495 | num4.setText(""); 496 | num4.setBounds(230, 210, 70, 50); 497 | num4.setFont(new Font("", Font.BOLD, 40)); 498 | num4.setForeground(Color.BLACK); 499 | num3.setText(""); 500 | num3.setBounds(230, 110, 70, 50); 501 | num3.setFont(new Font("", Font.BOLD, 40)); 502 | num3.setForeground(Color.cyan); 503 | num2.setText(""); 504 | num2.setBounds(230, 10, 70, 50); 505 | num2.setFont(new Font("", Font.BOLD, 40)); 506 | num2.setForeground(Color.orange); 507 | num1.setText("0"); 508 | num1.setBounds(30, 60, 70, 50); 509 | num1.setFont(new Font("", Font.BOLD, 40)); 510 | num1.setForeground(Color.BLUE); 511 | 512 | numMin.setText("10"); 513 | numMin.setBounds(330, 60, 70, 50); 514 | numMin.setFont(new Font("", Font.BOLD, 40)); 515 | numMin.setForeground(Color.BLUE); 516 | numMax.setText("50"); 517 | numMax.setBounds(430, 60, 70, 50); 518 | numMax.setFont(new Font("", Font.BOLD, 40)); 519 | numMax.setForeground(Color.BLUE); 520 | 521 | JLabel label1 = new JLabel("(相似化)"); 522 | label1.setToolTipText("不建议使用,因为需要极大内存"); 523 | JLabel label2 = new JLabel("像素移动:"); 524 | JLabel label2x = new JLabel("0 to 100"); 525 | JLabel label3 = new JLabel("亮度:"); 526 | JLabel label3x = new JLabel("0 to 100"); 527 | JLabel label4 = new JLabel("色彩取整:"); 528 | JLabel label4x = new JLabel("1 to 100"); 529 | JLabel label5 = new JLabel("色调:"); 530 | JLabel label5x = new JLabel("-100 to 100"); 531 | JLabel label6 = new JLabel("随机加色:"); 532 | JLabel label6x = new JLabel("0 to 100"); 533 | JLabel label7 = new JLabel("(边缘)"); 534 | label7.setToolTipText(" Use calculated edge to present the picture,it is useful when compared to (ColorDelta)"); 535 | JLabel label8 = new JLabel("边缘模式:"); 536 | JLabel label9 = new JLabel("修复次数"); 537 | JLabel label10 = new JLabel("边缘大小"); 538 | JLabel label12 = new JLabel("模糊"); 539 | 540 | label2x.setBounds(330, 10, 150, 50); 541 | label2x.setFont(new Font("", Font.BOLD, 30)); 542 | label3x.setBounds(330, 110, 150, 50); 543 | label3x.setFont(new Font("", Font.BOLD, 30)); 544 | label4x.setBounds(330, 210, 150, 50); 545 | label4x.setFont(new Font("", Font.BOLD, 30)); 546 | label5x.setBounds(310, 310, 190, 50); 547 | label5x.setFont(new Font("", Font.BOLD, 30)); 548 | label6x.setBounds(330, 410, 150, 50); 549 | label6x.setFont(new Font("", Font.BOLD, 30)); 550 | 551 | 552 | label1.setBounds(30, 10, 490, 50); 553 | label1.setFont(new Font("", Font.BOLD, 20)); 554 | label2.setBounds(30, 10, 200, 50); 555 | label2.setFont(new Font("", Font.BOLD, 35)); 556 | label3.setBounds(30, 110, 200, 50); 557 | label3.setFont(new Font("", Font.BOLD, 33)); 558 | label4.setBounds(30, 210, 200, 50); 559 | label4.setFont(new Font("", Font.BOLD, 25)); 560 | label5.setBounds(45, 310, 200, 50); 561 | label5.setFont(new Font("", Font.BOLD, 40)); 562 | label6.setBounds(30, 410, 200, 50); 563 | label6.setFont(new Font("", Font.BOLD, 21)); 564 | label7.setBounds(30, 210, 190, 50); 565 | label7.setFont(new Font("", Font.BOLD, 20)); 566 | label8.setBounds(20, 350, 230, 50); 567 | label8.setFont(new Font("", Font.BOLD, 22)); 568 | label9.setBounds(350, 320, 90, 50); 569 | label9.setFont(new Font("", Font.BOLD, 15)); 570 | label10.setBounds(450, 320, 90, 50); 571 | label10.setFont(new Font("", Font.BOLD, 15)); 572 | label12.setBounds(450, 420, 90, 50); 573 | label12.setFont(new Font("", Font.BOLD, 17)); 574 | 575 | panel4th.add(num11); 576 | panel4th.add(num13); 577 | panel4th.add(num14); 578 | panel4th.add(fill); 579 | panel4th.add(pixel); 580 | 581 | panel1st.add(num12); 582 | panel1st.add(label12); 583 | 584 | this.add(tabbedPane); 585 | panel1st.add(label1); 586 | 587 | panel2nd.add(label2); 588 | panel2nd.add(label3); 589 | panel2nd.add(label4); 590 | panel2nd.add(label5); 591 | panel2nd.add(label6); 592 | 593 | panel2nd.add(label2x); 594 | panel2nd.add(label3x); 595 | panel2nd.add(label4x); 596 | panel2nd.add(label5x); 597 | panel2nd.add(label6x); 598 | 599 | panel1st.add(label7); 600 | panel1st.add(label8); 601 | panel1st.add(label9); 602 | panel1st.add(label10); 603 | panel1st.add(numMax); 604 | panel1st.add(numMin); 605 | panel1st.add(num1); 606 | panel2nd.add(num2); 607 | panel2nd.add(num3); 608 | panel2nd.add(num4); 609 | panel2nd.add(num5); 610 | panel2nd.add(num6); 611 | panel1st.add(num7); 612 | panel1st.add(num9); 613 | panel1st.add(num10); 614 | this.add(Cal); 615 | this.add(Cal1); 616 | this.add(load); 617 | } 618 | 619 | private void Change() { 620 | BufferedImage img3 = img1; 621 | img1 = img; 622 | img = img3; 623 | panel.repaint(); 624 | panel1.repaint(); 625 | } 626 | 627 | private void initImg(File file) { 628 | try { 629 | img2 = ImageIO.read(file); 630 | img = ImageIO.read(file); 631 | if (times <= fillFrame) { 632 | img1 = ImageIO.read(file); 633 | imgLast = img1; 634 | } else { 635 | imgLast = img1; 636 | img1 = ImageIO.read(file); 637 | } 638 | } catch (IOException e) { 639 | if (times <= 1) 640 | JOptionPane.showMessageDialog(null, "图片丢失"); 641 | else 642 | JOptionPane.showMessageDialog(null, "成功生成"); 643 | stop = true; 644 | } 645 | } 646 | 647 | /** 648 | * -----------------模糊算法------------------------------------------------------------------------- 649 | */ 650 | private void calculate(int x, int y, double a[][][], int changeValue) { 651 | 652 | r = a[x][y][1]; 653 | g = a[x][y][2]; 654 | b = a[x][y][3]; 655 | try { 656 | if (x - 1 > 0) 657 | calculate2(x - 1, y, a, changeValue); 658 | if (y - 1 > 0) 659 | calculate2(x, y - 1, a, changeValue); 660 | if (x + 1 < width) 661 | calculate2(x + 1, y, a, changeValue); 662 | if (y + 1 < height) 663 | calculate2(x, y + 1, a, changeValue); 664 | 665 | } catch (Exception e) { 666 | } 667 | a[x][y][0] = 2; 668 | a[x][y][0] = 3; 669 | a[x][y][1] = CalculateTotal[0]; 670 | a[x][y][2] = CalculateTotal[1]; 671 | a[x][y][3] = CalculateTotal[2]; 672 | } 673 | 674 | private void calculate2(int x, int y, double a[][][], int changeValue) { 675 | 676 | if (a[x][y][0] <= 0) { 677 | double delta = Math.abs(a[x][y][1] - r) + Math.abs(a[x][y][2] - g) + Math.abs(a[x][y][3] - b); 678 | if (delta < changeValue) { 679 | a[x][y][0] = 1; 680 | try { 681 | calculate(x, y, a, changeValue); 682 | } catch (Exception e) { 683 | } 684 | } else { 685 | a[x][y][0] = -1; 686 | } 687 | } 688 | 689 | } 690 | 691 | /** 692 | * ----------------------边缘算法-------------------------------------------------------------------- 693 | */ 694 | 695 | 696 | private void calculate11(int x, int y, double a[][][], int changeValue) { 697 | 698 | 699 | r = a[x][y][1]; 700 | g = a[x][y][2]; 701 | b = a[x][y][3]; 702 | a[x][y][0] = 2; 703 | a[x][y][1] = CalculateTotal[0]; 704 | a[x][y][2] = CalculateTotal[1]; 705 | a[x][y][3] = CalculateTotal[2]; 706 | try { 707 | if (x - 1 > 0) 708 | calculate12(x - 1, y, a, changeValue); 709 | if (y - 1 > 0) 710 | calculate12(x, y - 1, a, changeValue); 711 | if (x + 1 < width) 712 | calculate12(x + 1, y, a, changeValue); 713 | if (y + 1 < height) 714 | calculate12(x, y + 1, a, changeValue); 715 | 716 | } catch (Exception e) { 717 | } 718 | 719 | } 720 | 721 | private void calculate12(int x, int y, double a[][][], int changeValue) { 722 | 723 | if (a[x][y][0] == 0) { 724 | calculate11(x, y, a, changeValue); 725 | } 726 | 727 | } 728 | 729 | /** 730 | * ------------------------------------------------------------------------------------------ 731 | */ 732 | 733 | private double findEdgePercent(int valueOfChange, double xxx[][][]) { 734 | double a[][][] = xxx; 735 | double value11; 736 | if (valueOfChange > 0) { 737 | value11 = 0; 738 | for (int x = 1; x < img1.getWidth() - 1; x++) { 739 | for (int y = 1; y < img1.getHeight() - 1; y++) { 740 | 741 | double delta = Math.abs(a[x][y][1] - a[x + 1][y][1]) + Math.abs(a[x][y][2] - a[x + 1][y][2]) + Math.abs(a[x][y][3] - a[x + 1][y][3]); 742 | if (delta > valueOfChange) { 743 | value11++; 744 | continue; 745 | } 746 | delta = Math.abs(a[x][y][1] - a[x - 1][y][1]) + Math.abs(a[x][y][2] - a[x - 1][y][2]) + Math.abs(a[x][y][3] - a[x - 1][y][3]); 747 | if (delta > valueOfChange) { 748 | value11++; 749 | continue; 750 | } 751 | delta = Math.abs(a[x][y][1] - a[x][y + 1][1]) + Math.abs(a[x][y][2] - a[x][y + 1][2]) + Math.abs(a[x][y][3] - a[x][y + 1][3]); 752 | if (delta > valueOfChange) { 753 | value11++; 754 | continue; 755 | } 756 | delta = Math.abs(a[x][y][1] - a[x][y - 1][1]) + Math.abs(a[x][y][2] - a[x][y - 1][2]) + Math.abs(a[x][y][3] - a[x][y - 1][3]); 757 | if (delta > valueOfChange) { 758 | value11++; 759 | continue; 760 | } 761 | } 762 | } 763 | value11 = value11 * 100 / img1.getWidth() / img1.getHeight(); 764 | return value11; 765 | } 766 | return 0; 767 | } 768 | 769 | /** 770 | * ------------------------------------------------------------------------------------------ 771 | */ 772 | private int findPerfectValue(double a[][][]) { 773 | int change = 0; 774 | 775 | 776 | if (edgeTestMethod.getSelectedIndex() % 2 == 1) { 777 | int in = 5; 778 | while (in < 400) { 779 | if (findEdgePercent(in, a) < 80) { 780 | change = in; 781 | break; 782 | } 783 | in = (int) (in * 1.2); 784 | } 785 | } 786 | 787 | 788 | if (edgeTestMethod.getSelectedIndex() % 2 == 0) { 789 | while (true) { 790 | if (findEdgePercent(1, a) < 60) { 791 | change = 1; 792 | break; 793 | } 794 | double i2 = findEdgePercent(2, a); 795 | double i3 = findEdgePercent(3, a); 796 | if (i2 < 66) { 797 | change = 2; 798 | break; 799 | } 800 | if (i2 - i3 > 30) { 801 | change = 2; 802 | break; 803 | } 804 | if (i2 - i3 > 25 && i2 > 80) { 805 | change = 2; 806 | break; 807 | } 808 | if (findEdgePercent(3, a) < 66) { 809 | change = 3; 810 | break; 811 | } 812 | if (findEdgePercent(4, a) < 66) { 813 | change = 4; 814 | 815 | break; 816 | } 817 | if (findEdgePercent(5, a) < 66) { 818 | change = 5; 819 | break; 820 | } 821 | if (findEdgePercent(6, a) < 70) { 822 | change = 6; 823 | break; 824 | } 825 | int in = 7; 826 | while (in < 100) { 827 | if (findEdgePercent(in, a) < 80) { 828 | change = in; 829 | break; 830 | } 831 | in = (int) (in * 1.2); 832 | } 833 | break; 834 | } 835 | } 836 | value = findEdgePercent(change, a); 837 | return change; 838 | } 839 | 840 | 841 | public static void heapSort2(int[][] a) { 842 | for (int i = a.length / 2 - 1; i >= 0; i--) { 843 | adjustHeap2(a, i, a.length); 844 | } 845 | for (int j = a.length - 1; j > 0; j--) { 846 | swap2(a, 0, j); 847 | adjustHeap2(a, 0, j); 848 | } 849 | 850 | } 851 | 852 | public static void adjustHeap2(int[][] a, int i, int length) { 853 | int temp[] = a[i].clone(); 854 | for (int k = i * 2 + 1; k < length; k = k * 2 + 1) { 855 | if (k + 1 < length && a[k][1] < a[k + 1][1]) { 856 | k++; 857 | } 858 | if (a[k][1] > temp[1]) { 859 | a[i][0] = a[k][0]; 860 | a[i][1] = a[k][1]; 861 | a[i][2] = a[k][2]; 862 | a[i][3] = a[k][3]; 863 | a[i][4] = a[k][4]; 864 | i = k; 865 | } else { 866 | break; 867 | } 868 | } 869 | a[i] = temp.clone(); 870 | } 871 | 872 | public static void swap2(int[][] a, int a1, int a2) { 873 | int temp[] = new int[5]; 874 | temp[1] = a[a1][1]; 875 | a[a1][1] = a[a2][1]; 876 | a[a2][1] = temp[1]; 877 | 878 | temp[0] = a[a1][0]; 879 | a[a1][0] = a[a2][0]; 880 | a[a2][0] = temp[0]; 881 | 882 | temp[2] = a[a1][2]; 883 | a[a1][2] = a[a2][2]; 884 | a[a2][2] = temp[2]; 885 | 886 | temp[3] = a[a1][3]; 887 | a[a1][3] = a[a2][3]; 888 | a[a2][3] = temp[3]; 889 | 890 | temp[4] = a[a1][4]; 891 | a[a1][4] = a[a2][4]; 892 | a[a2][4] = temp[4]; 893 | } 894 | 895 | /** 896 | * 处理图片 897 | */ 898 | private void processImg(int changeValue, int moveValue, int light, int n4, int n5, int n6, int n7, int n8, int n9, int n10, int n11) { 899 | 900 | 901 | double a[][][] = new double[img1.getWidth()][img1.getHeight()][4];//0---value;1----red;2---green;3--blue 902 | double a1[][][] = new double[img1.getWidth()][img1.getHeight()][4];//0---value;1----red;2---green;3--blue 903 | 904 | width = img1.getWidth(); 905 | height = img1.getHeight(); 906 | 907 | for (int x = 0; x < img1.getWidth(); x++) { 908 | for (int y = 0; y < img1.getHeight(); y++) { 909 | // find rgb 910 | int rgb = img1.getRGB(x, y); 911 | int rgbLast = imgLast.getRGB(x, y); 912 | Color color = new Color(rgb); 913 | Color colorLast = new Color(rgbLast); 914 | 915 | if (fillFrame == 1) { 916 | a[x][y][1] = color.getRed(); 917 | a[x][y][2] = color.getGreen(); 918 | a[x][y][3] = color.getBlue(); 919 | } else { 920 | double percent = times / fillFrame - (int) (times / fillFrame); 921 | 922 | a[x][y][1] = color.getRed() * percent + colorLast.getRed() * (1 - percent); 923 | a[x][y][2] = color.getGreen() * percent + colorLast.getGreen() * (1 - percent); 924 | a[x][y][3] = color.getBlue() * percent + colorLast.getBlue() * (1 - percent); 925 | 926 | } 927 | 928 | 929 | if (removeBlackWhite.isSelected()) { 930 | if (color.getBlue() + color.getGreen() + color.getRed() < 600 && color.getBlue() + color.getGreen() + color.getRed() > 450 && Math.abs(color.getGreen() - color.getRed()) + color.getBlue() + color.getGreen() < 30) {// 765 white 931 | a[x][y][0] = 4; 932 | } 933 | } 934 | if (removeBilibili.isSelected()) 935 | if (x * 100 / width >= 87 && x * 100 / width <= 96 && y * 100 / height <= 11 && y * 100 / height >= 5 && color.getBlue() + color.getGreen() + color.getRed() > 200) {// 765 white 936 | a[x][y][0] = 4; 937 | } // remove " bilibili " 938 | } 939 | } 940 | /** 941 | * -----------------find proper changeValue------------------------------------------------------------------------ 942 | */ 943 | if (auto1.isSelected()) { 944 | changeValue = findPerfectValue(a); 945 | lab1.setText("值:" + changeValue + " 百分比:" + value); 946 | } 947 | if (auto2.isSelected()) { 948 | n7 = findPerfectValue(a); 949 | lab2.setText("值:" + n7 + " 百分比:" + value); 950 | } 951 | /** 952 | * -----------------模糊算法------------------------------------------------------------------------- 953 | */ 954 | if (changeValue > 0) { 955 | value = 0; 956 | /** 957 | * 边缘算法 ~~ 958 | */ 959 | for (int x = 1; x < img1.getWidth() - 1; x++) { 960 | for (int y = 1; y < img1.getHeight() - 1; y++) { 961 | if (edgeTestMethod.getSelectedIndex() == 0) { 962 | double delta = Math.abs(a[x][y][1] - a[x + 1][y][1]) + Math.abs(a[x][y][2] - a[x + 1][y][2]) + Math.abs(a[x][y][3] - a[x + 1][y][3]); 963 | if (delta > changeValue) 964 | a[x][y][0] = 4; 965 | delta = Math.abs(a[x][y][1] - a[x - 1][y][1]) + Math.abs(a[x][y][2] - a[x - 1][y][2]) + Math.abs(a[x][y][3] - a[x - 1][y][3]); 966 | if (delta > changeValue) 967 | a[x][y][0] = 4; 968 | delta = Math.abs(a[x][y][1] - a[x][y + 1][1]) + Math.abs(a[x][y][2] - a[x][y + 1][2]) + Math.abs(a[x][y][3] - a[x][y + 1][3]); 969 | if (delta > changeValue) 970 | a[x][y][0] = 4; 971 | delta = Math.abs(a[x][y][1] - a[x][y - 1][1]) + Math.abs(a[x][y][2] - a[x][y - 1][2]) + Math.abs(a[x][y][3] - a[x][y - 1][3]); 972 | if (delta > changeValue) 973 | a[x][y][0] = 4; 974 | } 975 | 976 | if (edgeTestMethod.getSelectedIndex() == 1) { 977 | double dx = 0, dy = 0; 978 | for (int i = 1; i < 4; i++) { 979 | dx += Math.abs(a[x - 1][y][i] + a[x - 1][y - 1][i] + a[x - 1][y + 1][i] - a[x + 1][y][i] - a[x + 1][y - 1][i] - a[x + 1][y + 1][i]); 980 | dy += Math.abs(a[x][y - 1][i] + a[x - 1][y - 1][i] + a[x + 1][y - 1][i] - a[x][y + 1][i] - a[x - 1][y + 1][i] - a[x + 1][y + 1][i]); 981 | } 982 | double delta = Math.sqrt(dx * dx + dy * dy) / 10; 983 | if (delta > changeValue) 984 | a[x][y][0] = 4; 985 | } 986 | 987 | if (a[x][y][0] == 4) { 988 | value++; 989 | } 990 | } 991 | } 992 | value = value * 100 / img1.getWidth() / img1.getHeight(); 993 | if (!auto1.isSelected()) lab1.setText(" Percent:" + value); 994 | /** 995 | * 996 | */ 997 | for (int x = 1; x < img1.getWidth() - 1; x++) { 998 | for (int y = 1; y < img1.getHeight() - 1; y++) { 999 | if (a[x][y][0] == 4) { 1000 | continue; 1001 | } 1002 | if (a[x][y][0] == -1) a[x][y][0] = 0; 1003 | if (a[x][y][0] != 0) continue; 1004 | if (a[x][y][0] == 0) { 1005 | CalculateTotal = new double[]{a[x][y][1], a[x][y][2], a[x][y][3]}; 1006 | calculate11(x, y, a, changeValue); 1007 | } 1008 | 1009 | } 1010 | } 1011 | } 1012 | /** 1013 | * --------------------------------n色绘制----------------------------------------------------------------- 1014 | */ 1015 | if (colorLimit.isSelected()) { 1016 | int numOfColor = 0; 1017 | int color10[][] = new int[27 * 27 * 27][5];//0 index,1=number,2-4 rgb 1018 | for (int i = 0; i < 27 * 27 * 27; i++) { 1019 | color10[i][0] = i; 1020 | } 1021 | 1022 | for (int x1 = 0; x1 < img1.getWidth(); x1++) { 1023 | for (int y1 = 0; y1 < img1.getHeight(); y1++) { 1024 | 1025 | int a00 = (int) (a[x1][y1][1] / 10) + 27 * (int) (a[x1][y1][2] / 10) + 27 * 27 * (int) (a[x1][y1][3] / 10); 1026 | color10[a00][1]++; 1027 | color10[a00][2] += a[x1][y1][1]; 1028 | color10[a00][3] += a[x1][y1][2]; 1029 | color10[a00][4] += a[x1][y1][3]; 1030 | } 1031 | } 1032 | int dot = width * height; 1033 | int recent = 0; 1034 | heapSort2(color10); 1035 | 1036 | for (int i = 27 * 27 * 27 - 1; i > 0; i--) { 1037 | recent += color10[i][1]; 1038 | numOfColor++; 1039 | if (color10[i][1] > 0) { 1040 | color10[i][2] = color10[i][2] / color10[i][1]; 1041 | color10[i][3] = color10[i][3] / color10[i][1]; 1042 | color10[i][4] = color10[i][4] / color10[i][1]; 1043 | } 1044 | int aax = 2; 1045 | if (ColorChoose.getSelectedIndex() == 1) aax = 3; 1046 | if (ColorChoose.getSelectedIndex() == 2) aax = 5; 1047 | if (ColorChoose.getSelectedIndex() == 3) aax = 7; 1048 | if (ColorChoose.getSelectedIndex() == 4) aax = 10; 1049 | if ((numOfColor > colorMin && recent > dot / aax) || numOfColor > colorMax) break; 1050 | } 1051 | 1052 | 1053 | for (int x1 = 0; x1 < img1.getWidth(); x1++) { 1054 | for (int y1 = 0; y1 < img1.getHeight(); y1++) { 1055 | double max = 99999; 1056 | int colors[] = new int[4]; 1057 | for (int i = 27 * 27 * 27 - 1; i > 27 * 27 * 27 - 1 - numOfColor; i--) { 1058 | double delta = Math.abs(a[x1][y1][1] - color10[i][2]) + Math.abs(a[x1][y1][2] - color10[i][3]) + Math.abs(a[x1][y1][3] - color10[i][4]); 1059 | if (delta < max) { 1060 | colors[1] = color10[i][2]; 1061 | colors[2] = color10[i][3]; 1062 | colors[3] = color10[i][4]; 1063 | max = delta; 1064 | } 1065 | } 1066 | 1067 | int aac = 100; 1068 | if (ColorChoose1.getSelectedIndex() == 1) aac = 50; 1069 | if (ColorChoose1.getSelectedIndex() == 2) aac = 30; 1070 | if (ColorChoose1.getSelectedIndex() == 3) aac = 20; 1071 | if (ColorChoose1.getSelectedIndex() == 4) aac = 10; 1072 | 1073 | if (max > aac) a[x1][y1][0] = 4; 1074 | a[x1][y1][1] = colors[1]; 1075 | a[x1][y1][2] = colors[2]; 1076 | a[x1][y1][3] = colors[3]; 1077 | 1078 | } 1079 | } 1080 | } 1081 | /** 1082 | * ---------------边缘---------------------------------------------------------------------------------- 1083 | */ 1084 | value = 0; 1085 | if (n7 > 0) { 1086 | for (int x = 1; x < img1.getWidth() - 1; x++) { 1087 | for (int y = 1; y < img1.getHeight() - 1; y++) { 1088 | double n77 = n7; 1089 | if (blackFirst.isSelected()) { 1090 | n77 = n7 * ((a[x][y][1] + a[x][y][2] + a[x][y][3]) / 255 / 3 * 1 * 2 + 0); 1091 | } 1092 | 1093 | if (edgeTestMethod.getSelectedIndex() == 2) { 1094 | a[x][y][0] = 4; 1095 | double delta = Math.abs(a[x][y][1] - a[x + 1][y][1]) + Math.abs(a[x][y][2] - a[x + 1][y][2]) + Math.abs(a[x][y][3] - a[x + 1][y][3]); 1096 | if (delta > n77) { 1097 | delta = Math.abs(a[x][y][1] - a[x - 1][y][1]) + Math.abs(a[x][y][2] - a[x - 1][y][2]) + Math.abs(a[x][y][3] - a[x - 1][y][3]); 1098 | if (delta > n77) { 1099 | delta = Math.abs(a[x][y][1] - a[x][y + 1][1]) + Math.abs(a[x][y][2] - a[x][y + 1][2]) + Math.abs(a[x][y][3] - a[x][y + 1][3]); 1100 | if (delta > n77) { 1101 | delta = Math.abs(a[x][y][1] - a[x][y - 1][1]) + Math.abs(a[x][y][2] - a[x][y - 1][2]) + Math.abs(a[x][y][3] - a[x][y - 1][3]); 1102 | if (delta > n77) 1103 | a[x][y][0] = 0; 1104 | } 1105 | } 1106 | } 1107 | } 1108 | if (edgeTestMethod.getSelectedIndex() == 0) { 1109 | double delta = Math.abs(a[x][y][1] - a[x + 1][y][1]) + Math.abs(a[x][y][2] - a[x + 1][y][2]) + Math.abs(a[x][y][3] - a[x + 1][y][3]); 1110 | if (delta > n77) 1111 | a[x][y][0] = 4; 1112 | delta = Math.abs(a[x][y][1] - a[x][y + 1][1]) + Math.abs(a[x][y][2] - a[x][y + 1][2]) + Math.abs(a[x][y][3] - a[x][y + 1][3]); 1113 | if (delta > n77) 1114 | a[x][y][0] = 4; 1115 | } 1116 | if (edgeTestMethod.getSelectedIndex() == 1) { 1117 | double dx = 0, dy = 0; 1118 | for (int i = 1; i < 4; i++) { 1119 | dx += Math.abs(a[x - 1][y][i] + a[x - 1][y - 1][i] + a[x - 1][y + 1][i] - a[x + 1][y][i] - a[x + 1][y - 1][i] - a[x + 1][y + 1][i]); 1120 | dy += Math.abs(a[x][y - 1][i] + a[x - 1][y - 1][i] + a[x + 1][y - 1][i] - a[x][y + 1][i] - a[x - 1][y + 1][i] - a[x + 1][y + 1][i]); 1121 | } 1122 | double delta = Math.sqrt(dx * dx + dy * dy) / 10; 1123 | if (delta > n77) 1124 | a[x][y][0] = 4; 1125 | } 1126 | if (edgeTestMethod.getSelectedIndex() == 3) { 1127 | double dx = 0, dy = 0; 1128 | for (int i = 1; i < 4; i++) { 1129 | dx += Math.abs(a[x - 1][y][i] + a[x - 1][y - 1][i] + a[x - 1][y + 1][i] - a[x + 1][y][i] - a[x + 1][y - 1][i] - a[x + 1][y + 1][i]); 1130 | dy += Math.abs(a[x][y - 1][i] + a[x - 1][y - 1][i] + a[x + 1][y - 1][i] - a[x][y + 1][i] - a[x - 1][y + 1][i] - a[x + 1][y + 1][i]); 1131 | } 1132 | double delta = Math.sqrt(dx * dx + dy * dy) / 10; 1133 | if (delta <= n77) 1134 | a[x][y][0] = 4; 1135 | } 1136 | } 1137 | } 1138 | 1139 | for (int x = 1; x < img1.getWidth() - 1; x++) { 1140 | for (int y = 1; y < img1.getHeight() - 1; y++) { 1141 | 1142 | if (removeBlackWhite.isSelected() && Math.abs(a[x][y][1] - a[x][y][2]) + Math.abs(a[x][y][2] - a[x][y][3]) < 20) { 1143 | int ax = 0; 1144 | for (int i = -1; i <= 1; i++) 1145 | for (int j = -1; j <= 1; j++) 1146 | if (a[x + i][y + j][0] == 4) ax++; 1147 | if (ax >= 7) 1148 | a[x][y][0] = 0.1; 1149 | } 1150 | 1151 | if (a[x][y][0] == 4 || a[x][y][0] == 0.1) { 1152 | a[x][y][0] = 4; 1153 | a[x][y][1] = op.getColor().getRed(); 1154 | a[x][y][2] = op.getColor().getGreen(); 1155 | a[x][y][3] = op.getColor().getBlue(); 1156 | value++; 1157 | } else { 1158 | if (removeForeground.isSelected()) { 1159 | a[x][y][1] = 255; 1160 | a[x][y][2] = 255; 1161 | a[x][y][3] = 255; 1162 | } 1163 | } 1164 | } 1165 | } 1166 | value = value * 100 / img1.getWidth() / img1.getHeight(); 1167 | if (!auto2.isSelected()) lab2.setText(" 百分比:" + value); 1168 | } 1169 | 1170 | 1171 | /** 1172 | * ------------------------------------------------------------------------------------------------- 1173 | */ 1174 | int n; 1175 | for (int x = 1; x < img1.getWidth() - 1; x++) { 1176 | for (int y = 1; y < img1.getHeight() - 1; y++) { 1177 | n = Math.min(Math.min(Math.min(x, y), Math.min(img1.getWidth() - x, img1.getHeight() - y)), 40);//n max==20 1178 | if (a[x][y][0] == 4) { 1179 | /** 1180 | *edge method 0==left Up 1==Search nearest 2==No (former) 1181 | */ 1182 | if (n8 == 0) { 1183 | if ((x + y) % 2 == 0) { 1184 | a[x][y][1] = a[x - 1][y][1]; 1185 | a[x][y][2] = a[x - 1][y][2]; 1186 | a[x][y][3] = a[x - 1][y][3]; 1187 | } else { 1188 | a[x][y][1] = a[x][y - 1][1]; 1189 | a[x][y][2] = a[x][y - 1][2]; 1190 | a[x][y][3] = a[x][y - 1][3]; 1191 | } 1192 | } 1193 | if (n8 == 1) { 1194 | if (edgeTestMethod.getSelectedIndex() < 2) { 1195 | if ((x + y) % 2 == 0) { 1196 | a[x][y][1] = a[x - 1][y][1]; 1197 | a[x][y][2] = a[x - 1][y][2]; 1198 | a[x][y][3] = a[x - 1][y][3]; 1199 | } else { 1200 | a[x][y][1] = a[x][y - 1][1]; 1201 | a[x][y][2] = a[x][y - 1][2]; 1202 | a[x][y][3] = a[x][y - 1][3]; 1203 | } 1204 | } else { 1205 | a[x][y][1] = 255; 1206 | a[x][y][2] = 255; 1207 | a[x][y][3] = 255; 1208 | } 1209 | a[x][y][1] = 255; 1210 | a[x][y][2] = 255; 1211 | a[x][y][3] = 255; 1212 | boolean con = false; 1213 | int nn = 3; 1214 | for (int m1 = 1; m1 < n; m1++) { 1215 | for (int m2 = 0; m2 <= m1; m2++) { 1216 | double ans = 0; 1217 | ans = a[x + m1 - m2][y + m2][1]; 1218 | if (a[x + m1 - m2][y + m2][0] < 3 && ans != 0 && ans < 230 && (Math.abs(ans - a[x + m1 - m2][y + m2][2]) > nn)) { 1219 | a[x][y][1] = a[x + m1 - m2][y + m2][1]; 1220 | a[x][y][2] = a[x + m1 - m2][y + m2][2]; 1221 | a[x][y][3] = a[x + m1 - m2][y + m2][3]; 1222 | con = true; 1223 | break; 1224 | } 1225 | ans = a[x - m1 + m2][y + m2][1]; 1226 | if (a[x - m1 + m2][y + m2][0] < 3 && ans != 0 && ans < 230 && Math.abs(ans - a[x - m1 + m2][y + m2][2]) > nn) { 1227 | a[x][y][1] = a[x - m1 + m2][y + m2][1]; 1228 | a[x][y][2] = a[x - m1 + m2][y + m2][2]; 1229 | a[x][y][3] = a[x - m1 + m2][y + m2][3]; 1230 | con = true; 1231 | break; 1232 | } 1233 | ans = a[x + m1 - m2][y - m2][1]; 1234 | if (a[x + m1 - m2][y - m2][0] < 3 && ans != 0 && ans < 230 && Math.abs(ans - a[x + m1 - m2][y - m2][2]) > nn) { 1235 | a[x][y][1] = a[x + m1 - m2][y - m2][1]; 1236 | a[x][y][2] = a[x + m1 - m2][y - m2][2]; 1237 | a[x][y][3] = a[x + m1 - m2][y - m2][3]; 1238 | con = true; 1239 | break; 1240 | } 1241 | ans = a[x - m1 + m2][y - m2][1]; 1242 | if (a[x - m1 + m2][y - m2][0] < 3 && ans != 0 && ans < 230 && Math.abs(ans - a[x - m1 + m2][y - m2][2]) > nn) { 1243 | a[x][y][1] = a[x - m1 + m2][y - m2][1]; 1244 | a[x][y][2] = a[x - m1 + m2][y - m2][2]; 1245 | a[x][y][3] = a[x - m1 + m2][y - m2][3]; 1246 | con = true; 1247 | break; 1248 | } 1249 | } 1250 | if (con) break; 1251 | } 1252 | } 1253 | a[x][y][0] = 3; 1254 | } 1255 | } 1256 | } 1257 | 1258 | 1259 | /** 1260 | * -----make edge smoothly-------------------------------------------------------------------------------------------- 1261 | */ 1262 | for (int nn9 = 0; nn9 < n9; nn9++) { 1263 | double c[][][] = new double[img1.getWidth()][img1.getHeight()][4]; 1264 | 1265 | if (n8 == 2) { // line edge 1266 | for (int x = 1; x < img1.getWidth() - 1; x++) { 1267 | for (int y = 1; y < img1.getHeight() - 1; y++) { 1268 | int q = 0; 1269 | q += (a[x][y][1] == a[x - 1][y][1]) ? 1 : 0; 1270 | q += (a[x][y][1] == a[x + 1][y][1]) ? 1 : 0; 1271 | q += (a[x][y][1] == a[x][y + 1][1]) ? 1 : 0; 1272 | q += (a[x][y][1] == a[x][y - 1][1]) ? 1 : 0; 1273 | q += (a[x][y][1] == a[x - 1][y - 1][1]) ? 1 : 0; 1274 | q += (a[x][y][1] == a[x + 1][y - 1][1]) ? 1 : 0; 1275 | q += (a[x][y][1] == a[x - 1][y + 1][1]) ? 1 : 0; 1276 | q += (a[x][y][1] == a[x + 1][y + 1][1]) ? 1 : 0; 1277 | c[x][y][1] = a[x][y][1]; 1278 | c[x][y][2] = a[x][y][2]; 1279 | c[x][y][3] = a[x][y][3]; 1280 | 1281 | if (q <= 3) { 1282 | c[x][y][1] = 255 - a[x][y][1]; 1283 | c[x][y][2] = 255 - a[x][y][2]; 1284 | c[x][y][3] = 255 - a[x][y][3]; 1285 | } 1286 | } 1287 | } 1288 | for (int x = 1; x < img1.getWidth() - 1; x++) { 1289 | for (int y = 1; y < img1.getHeight() - 1; y++) { 1290 | a[x][y][1] = c[x][y][1]; 1291 | a[x][y][2] = c[x][y][2]; 1292 | a[x][y][3] = c[x][y][3]; 1293 | } 1294 | } 1295 | } else { 1296 | for (int x = n10; x < img1.getWidth() - n10; x++) { 1297 | for (int y = n10; y < img1.getHeight() - n10; y++) { 1298 | int q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0; 1299 | for (int x1 = -n10; x1 <= n10; x1++) { 1300 | for (int y1 = -n10; y1 <= n10; y1++) { 1301 | q1 += (a[x + x1][y + y1][1] == a[x - 1][y][1]) ? 1 : 0; 1302 | q2 += (a[x + x1][y + y1][1] == a[x + 1][y][1]) ? 1 : 0; 1303 | q3 += (a[x + x1][y + y1][1] == a[x][y + 1][1]) ? 1 : 0; 1304 | q4 += (a[x + x1][y + y1][1] == a[x][y - 1][1]) ? 1 : 0; 1305 | q5 += (a[x + x1][y + y1][1] == a[x][y][1]) ? 1 : 0; 1306 | } 1307 | } 1308 | int q = Math.max(Math.max(Math.max(q1, q2), Math.max(q4, q3)), q5); 1309 | if (q5 == q || q < 2) { 1310 | System.arraycopy(a[x][y], 1, c[x][y], 1, 3); 1311 | continue; 1312 | } 1313 | if (q1 == q) { 1314 | System.arraycopy(a[x - 1][y], 1, c[x][y], 1, 3); 1315 | continue; 1316 | } 1317 | if (q2 == q) { 1318 | System.arraycopy(a[x + 1][y], 1, c[x][y], 1, 3); 1319 | continue; 1320 | } 1321 | if (q3 == q) { 1322 | System.arraycopy(a[x][y + 1], 1, c[x][y], 1, 3); 1323 | continue; 1324 | } 1325 | if (q4 == q) { 1326 | System.arraycopy(a[x][y - 1], 1, c[x][y], 1, 3); 1327 | continue; 1328 | } 1329 | 1330 | } 1331 | } 1332 | for (int x = n10; x < img1.getWidth() - n10; x++) { 1333 | for (int y = n10; y < img1.getHeight() - n10; y++) { 1334 | System.arraycopy(c[x][y], 1, a[x][y], 1, 3); 1335 | } 1336 | } 1337 | } 1338 | } 1339 | /** 1340 | * -----渐变 smoothly-------------------------------------------------------------------------------------------- 1341 | */ 1342 | if (smooth > 0) 1343 | if (smooth > 10) smooth = 10; 1344 | for (int x = 0; x < img1.getWidth(); x++) { 1345 | for (int y = 0; y < img1.getHeight(); y++) { 1346 | int t = 0; 1347 | int total[] = {0, 0, 0, 0}; 1348 | for (int x1 = x - smooth; x1 <= x + smooth; x1++) { 1349 | if (x1 < 0 || x1 >= img1.getWidth()) continue; 1350 | for (int y1 = y - smooth; y1 <= y + smooth; y1++) { 1351 | if (y1 < 0 || y1 >= img1.getHeight()) continue; 1352 | 1353 | int value = (similar.isSelected()) ? Math.max(changeValue, n7) + 10 : 999; 1354 | 1355 | if (Math.abs(a[x1][y1][1] - a[x][y][1]) + Math.abs(a[x1][y1][1] - a[x][y][1]) + Math.abs(a[x1][y1][1] - a[x][y][1]) < value) { 1356 | t++; 1357 | total[1] += a[x1][y1][1]; 1358 | total[2] += a[x1][y1][2]; 1359 | total[3] += a[x1][y1][3]; 1360 | } 1361 | } 1362 | } 1363 | if (t > 0) { 1364 | a[x][y][1] = total[1] / t; 1365 | a[x][y][2] = total[2] / t; 1366 | a[x][y][3] = total[3] / t; 1367 | } 1368 | } 1369 | } 1370 | 1371 | /** 1372 | * -----------------------------pixel像素化处理-------------------------------------------------------------------- 1373 | */ 1374 | 1375 | if (pixelValue > 1) 1376 | for (int x1 = 0; x1 < img1.getWidth() / pixelValue; x1++) { 1377 | for (int y1 = 0; y1 < img1.getHeight() / pixelValue; y1++) { 1378 | int all[] = new int[27 * 27 * 27]; 1379 | for (int x = 0; x < pixelValue; x++) { 1380 | for (int y = 0; y < pixelValue; y++) { 1381 | all[(int) (a[x1 * pixelValue + x][y1 * pixelValue + y][1] / 10) + 27 * (int) (a[x1 * pixelValue + x][y1 * pixelValue + y][2] / 10) + 27 * 27 * (int) (a[x1 * pixelValue + x][y1 * pixelValue + y][3] / 10)]++; 1382 | } 1383 | } 1384 | 1385 | 1386 | int rTotal = 0, gTotal = 0, bTotal = 0; 1387 | int max = 0; 1388 | for (int i = 0; i < 27 * 27 * 27; i++) { 1389 | if (all[i] > max) { 1390 | max = all[i]; 1391 | rTotal = i % 27 * 10; 1392 | gTotal = i / 27 % 27 * 10; 1393 | bTotal = i / 27 / 27 % 27 * 10; 1394 | } 1395 | } 1396 | 1397 | /* 1398 | for (int x = 0; x < pixelValue; x++) { 1399 | for (int y = 0; y < pixelValue; y++) { 1400 | rTotal += a[x1 * pixelValue + x][y1 * pixelValue + y][1]; 1401 | gTotal += a[x1 * pixelValue + x][y1 * pixelValue + y][2]; 1402 | bTotal += a[x1 * pixelValue + x][y1 * pixelValue + y][3]; 1403 | } 1404 | } 1405 | rTotal = rTotal / pixelValue / pixelValue; 1406 | gTotal = gTotal / pixelValue / pixelValue; 1407 | bTotal = bTotal / pixelValue / pixelValue; 1408 | */ 1409 | 1410 | for (int x = 0; x < pixelValue; x++) { 1411 | for (int y = 0; y < pixelValue; y++) { 1412 | a[x1 * pixelValue + x][y1 * pixelValue + y][1] = rTotal; 1413 | a[x1 * pixelValue + x][y1 * pixelValue + y][2] = gTotal; 1414 | a[x1 * pixelValue + x][y1 * pixelValue + y][3] = bTotal; 1415 | } 1416 | } 1417 | } 1418 | } 1419 | /** 1420 | * -----------------------------颜色改变-------------------------------------------------------------------- 1421 | * 1422 | * */ 1423 | if (colorChange.isSelected()) { 1424 | int rr1 = Integer.parseInt(r1.getText()), rr2 = Integer.parseInt(r2.getText()); 1425 | int gg1 = Integer.parseInt(g1.getText()), gg2 = Integer.parseInt(g2.getText()); 1426 | int bb1 = Integer.parseInt(b1.getText()), bb2 = Integer.parseInt(b2.getText()); 1427 | int rg11 = Integer.parseInt(rg1.getText()), rg12 = Integer.parseInt(rg2.getText()); 1428 | int gb11 = Integer.parseInt(gb1.getText()), gb12 = Integer.parseInt(gb2.getText()); 1429 | int R = op.getColor().getRed() - (rr1 + rr2) / 2; 1430 | int G = op.getColor().getGreen() - (gg1 + gg2) / 2; 1431 | int B = op.getColor().getBlue() - (bb1 + bb2) / 2; 1432 | for (int x = 0; x < img1.getWidth(); x++) { 1433 | for (int y = 0; y < img1.getHeight(); y++) { 1434 | if (a[x][y][1] <= rr2 && a[x][y][1] >= rr1 && a[x][y][2] <= gg2 && a[x][y][2] >= gg1 && a[x][y][3] <= bb2 && a[x][y][3] >= bb1) { 1435 | if ((a[x][y][1] - a[x][y][2]) <= rg12 && (a[x][y][1] - a[x][y][2]) >= rg11 && (a[x][y][2] - a[x][y][3]) <= gb12 && (a[x][y][2] - a[x][y][3]) >= gb11) { 1436 | a[x][y][1] += R; 1437 | a[x][y][2] += G; 1438 | a[x][y][3] += B; 1439 | } 1440 | } 1441 | } 1442 | } 1443 | } 1444 | /** 1445 | * -----------------------------基本处理-------------------------------------------------------------------- 1446 | */ 1447 | for (int x = 0; x < img1.getWidth(); x++) { 1448 | for (int y = 0; y < img1.getHeight(); y++) { 1449 | 1450 | 1451 | //像素移动+光波粒二象性 1452 | int x1, y1; 1453 | // if (lightsPoly2D.isSelected()) { 1454 | // double random = Math.random(); 1455 | // int moveValue2 = (int) ((((int) (Math.random() * 2)) * 2 - 1) * ((random * random) * (width / numOfPoly2D / 2))); 1456 | 1457 | // x1 = (int) (x + Math.random() * (moveValue) * 2 - (moveValue)); 1458 | // x1 += moveValue2; 1459 | // } else { 1460 | x1 = (int) (x + Math.random() * (moveValue) * 2 - (moveValue)); 1461 | // } 1462 | y1 = (int) (y + Math.random() * moveValue * 2 - moveValue); 1463 | 1464 | if (x1 > img1.getWidth() - 1) { 1465 | x1 = img1.getWidth() - 1; 1466 | } else if (x1 < 0) { 1467 | x1 = 0; 1468 | } 1469 | if (y1 > img1.getHeight() - 1) { 1470 | y1 = img1.getHeight() - 1; 1471 | } else if (y1 < 0) { 1472 | y1 = 0; 1473 | } 1474 | int r = ((int) (a[x1][y1][1] + Math.random() * n6 * 2 - n6 + light) / n4) * n4; 1475 | int g = ((int) (a[x1][y1][2] + Math.random() * n6 * 2 - n6 + light) / n4) * n4; 1476 | int b = ((int) (a[x1][y1][3] + Math.random() * n6 * 2 - n6 + light) / n4) * n4; 1477 | int average = (r + g + b) / 3; 1478 | r = r + (r - average) * (n5) / 100; 1479 | g = g + (g - average) * (n5) / 100; 1480 | b = b + (b - average) * (n5) / 100; 1481 | 1482 | //光的波粒二象性 1483 | int poly = 10; 1484 | if (lightsPoly2D.isSelected()) { 1485 | double xx = x; 1486 | r += poly * Math.sin((xx + n11 * times) * numOfPoly2D * 3.1415 / width); 1487 | g += poly * Math.sin((xx + n11 * times) * numOfPoly2D * 3.1415 / width); 1488 | b += poly * Math.sin((xx + n11 * times) * numOfPoly2D * 3.1415 / width); 1489 | } 1490 | 1491 | 1492 | if (twoDimensionCode.isSelected()) { 1493 | //二维码 1494 | x1 = x1 % 80 / 2; 1495 | y1 = y1 % 80 / 2; 1496 | if (x1 <= 8 && y1 <= 8) { 1497 | r = 255; 1498 | g = 255; 1499 | b = 255; 1500 | if (y1 < 8 && (x1 == 1 || x1 == 7)) { 1501 | r = 0; 1502 | g = 0; 1503 | b = 0; 1504 | } 1505 | if (x1 < 8 && (y1 == 1 || y1 == 7)) { 1506 | r = 0; 1507 | g = 0; 1508 | b = 0; 1509 | } 1510 | if (x1 <= 5 && x1 >= 3 && y1 <= 5 && y1 >= 3) { 1511 | r = 0; 1512 | g = 0; 1513 | b = 0; 1514 | } 1515 | } 1516 | if (x1 >= 32 && y1 <= 8) { 1517 | x1 = x1 - 32; 1518 | r = 255; 1519 | g = 255; 1520 | b = 255; 1521 | if (y1 < 8 && (x1 == 1 || x1 == 7)) { 1522 | r = 0; 1523 | g = 0; 1524 | b = 0; 1525 | } 1526 | if (x1 < 8 && (y1 == 1 || y1 == 7)) { 1527 | r = 0; 1528 | g = 0; 1529 | b = 0; 1530 | } 1531 | if (x1 <= 5 && x1 >= 3 && y1 <= 5 && y1 >= 3) { 1532 | r = 0; 1533 | g = 0; 1534 | b = 0; 1535 | } 1536 | } 1537 | if (y1 >= 32 && x1 <= 8) { 1538 | y1 = y1 - 32; 1539 | r = 255; 1540 | g = 255; 1541 | b = 255; 1542 | if (y1 < 8 && (x1 == 1 || x1 == 7)) { 1543 | r = 0; 1544 | g = 0; 1545 | b = 0; 1546 | } 1547 | if (x1 < 8 && (y1 == 1 || y1 == 7)) { 1548 | r = 0; 1549 | g = 0; 1550 | b = 0; 1551 | } 1552 | if (x1 <= 5 && x1 >= 3 && y1 <= 5 && y1 >= 3) { 1553 | r = 0; 1554 | g = 0; 1555 | b = 0; 1556 | } 1557 | } 1558 | if (y1 >= 31 && y1 <= 35 && x1 >= 31 && x1 <= 35) { 1559 | r = 255; 1560 | g = 255; 1561 | b = 255; 1562 | if (x1 == 31 || x1 == 35) { 1563 | r = 0; 1564 | g = 0; 1565 | b = 0; 1566 | } 1567 | if (y1 == 31 || y1 == 35) { 1568 | r = 0; 1569 | g = 0; 1570 | b = 0; 1571 | } 1572 | if (x1 == 33 && y1 == 33) { 1573 | r = 0; 1574 | g = 0; 1575 | b = 0; 1576 | } 1577 | } 1578 | if (x1 == 0 || y1 == 0) { 1579 | r = 255; 1580 | g = 255; 1581 | b = 255; 1582 | } 1583 | } 1584 | //----------------------------------------- 1585 | if (r > 255) { 1586 | r = 255; 1587 | } else if (r < 0) { 1588 | r = 0; 1589 | } 1590 | if (g > 255) { 1591 | g = 255; 1592 | } else if (g < 0) { 1593 | g = 0; 1594 | } 1595 | if (b > 255) { 1596 | b = 255; 1597 | } else if (b < 0) { 1598 | b = 0; 1599 | } 1600 | 1601 | 1602 | if (onlyBlackAndWhite.isSelected()) {//黑白模式 1603 | int total = r + g + b; 1604 | 1605 | 1606 | if (total > 382) { 1607 | r = 255; 1608 | g = 255; 1609 | b = 255; 1610 | } else { 1611 | r = 0; 1612 | g = 0; 1613 | b = 0; 1614 | } 1615 | } 1616 | 1617 | Color color = new Color(r, g, b); 1618 | img.setRGB(x, y, color.getRGB()); 1619 | 1620 | } 1621 | } 1622 | 1623 | if (contract.isSelected()) { 1624 | for (int x = 0; x < img1.getWidth() / 2; x++) { 1625 | for (int y = 0; y < img1.getHeight() / 2; y++) { 1626 | img2.setRGB(x, y, img1.getRGB(2 * x, 2 * y)); 1627 | } 1628 | } 1629 | for (int x = img1.getWidth() / 2; x < img1.getWidth(); x++) { 1630 | for (int y = 0; y < img1.getHeight() / 2; y++) { 1631 | img2.setRGB(x, y, new Color(0, 0, 0).getRGB()); 1632 | } 1633 | } 1634 | for (int x = 0; x < img1.getWidth() / 2; x++) { 1635 | for (int y = img1.getHeight() / 2; y < img1.getHeight(); y++) { 1636 | img2.setRGB(x, y, new Color(0, 0, 0).getRGB()); 1637 | } 1638 | } 1639 | for (int x = (img1.getWidth() + 1) / 2; x < img1.getWidth(); x++) { 1640 | for (int y = (img1.getHeight() + 1) / 2; y < img1.getHeight(); y++) { 1641 | img2.setRGB(x, y, img.getRGB((x - (width + 1) / 2) * 2, (y - (height + 1) / 2) * 2)); 1642 | } 1643 | } 1644 | try { 1645 | if (times < 10) 1646 | ImageIO.write(img2, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/x000" + times + ".jpg")); 1647 | else if (times < 100) 1648 | ImageIO.write(img2, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/x00" + times + ".jpg")); 1649 | else if (times < 1000) 1650 | ImageIO.write(img2, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/x0" + times + ".jpg")); 1651 | else 1652 | ImageIO.write(img2, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/x" + times + ".jpg")); 1653 | 1654 | } catch (IOException e) { 1655 | e.printStackTrace(); 1656 | } 1657 | } 1658 | //------------------------------------------------------------------ 1659 | try { 1660 | if (times < 10) 1661 | ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/000" + times + ".jpg")); 1662 | else if (times < 100) 1663 | ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/00" + times + ".jpg")); 1664 | else if (times < 1000) 1665 | ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/0" + times + ".jpg")); 1666 | else 1667 | ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/" + times + ".jpg")); 1668 | System.out.println("图片" + times + "转化完成!"); 1669 | } catch (IOException e) { 1670 | e.printStackTrace(); 1671 | } 1672 | 1673 | 1674 | panel.repaint(); 1675 | } 1676 | 1677 | public static void main(String[] args) { 1678 | new color(); 1679 | 1680 | } 1681 | 1682 | } 1683 | 1684 | 1685 | -------------------------------------------------------------------------------- /color2.java: -------------------------------------------------------------------------------- 1 | 2 | import javax.imageio.ImageIO; 3 | import javax.swing.*; 4 | import javax.swing.filechooser.FileNameExtensionFilter; 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | import java.awt.image.BufferedImage; 8 | import java.io.File; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.time.LocalDateTime; 12 | import java.util.*; 13 | 14 | /* 15 | 制作by 零殇_Fan 16 | -------------------------------- 17 | 1.新功能:二次元魔法变天【选择图片特定部分的区块,用颜色或者贴图替换】 18 | 可以使用颜色替换和贴图替换(贴图也要jpg) 19 | 在计算方式1中,选完参数后直接点击图片上你想要更改的地方就能替换;计算方式2中,点击预览或者生成键自动替换 20 | 2.消除了部分bug,增加只描绘黑线的选项 21 | 3.图片自适应 22 | 23 | 2021/2/12 24 | -------------------------------- 25 | 更新了不少内容: 26 | 1.描绘两次的功能 27 | 2.功能可以在界面上直接调整 28 | 3.描线防锯齿 29 | 4.增加参数,使生成更多样化 30 | 31 | 2021/2/2 32 | --------------------------------- 33 | 图片现在支持jpg 34 | 参数调试板块还未完成,请先自行调下方的参数吧。 35 | 视频记得给个三连让更多人看到,关注up获得最新制作情报 36 | 37 | 最近期末周up有点忙,可能忙不过来。 38 | 反正视频播放越多更新越快咯 39 | 40 | 2020/12/10 41 | --------------------------------- 42 | */ 43 | 44 | public class color2 extends JFrame { 45 | 46 | static double percentIMG = 1; 47 | //-------------------page1----------------------------------------------------- 48 | int absBlack = 27, //黑边缘 49 | deltaColor = 15;//色 小的更精密 50 | int removeBlackPixel = 100;//移除少于此数量的单独的黑点 51 | int removeBlackPixel2 = 60;//移除黑色块的强度 52 | 53 | int notProcessColorIfNumLessThan = 5;//移除少于此数量的单独的色块 54 | 55 | double speed = 60;//描绘速度 56 | boolean paintNotPause = false;//上色不暂停 57 | 58 | 59 | boolean colorful = false;//自行随机涂颜色 60 | boolean black = true;//画黑线 61 | 62 | boolean blackTwice = true;//画两次黑线 63 | 64 | boolean removeBlackLast = true; 65 | boolean removeForNormal = false;//true用自带颜色替换、false用左边颜色替换 (替换小色块、 黑色块(如果上面是true)) 66 | 67 | private JComboBox jRemove = new JComboBox(new String[]{"不消除黑边", "自带颜色替换", "左边颜色替换"}); 68 | private JComboBox jColorful = new JComboBox(new String[]{"普通模式【不处理】", "魔幻色泽", "只勾黑边不上色"}); 69 | private JComboBox jBlackTwice = new JComboBox(new String[]{"不勾黑边", "勾一次黑边", "勾两次黑边"}); 70 | 71 | private JComboBox jQuick = new JComboBox(new String[]{"自行输入参数", "功能1:标准仅去近似色", "功能2:标准去字幕", "功能3:。。。"}); 72 | 73 | 74 | JSlider jSpeed = new JSlider(); 75 | JLabel jSpeedText2 = new JLabel("x99"); 76 | 77 | //-------------------page2----------------------------------------------------- 78 | JTabbedPane tabbedPane2ndDown = new JTabbedPane(); 79 | JTabbedPane tabbedPane2ColorMod = new JTabbedPane(); 80 | 81 | private static int mouseX = 0, mouseY = 0; 82 | private static int imgX = 0, imgY = 0; 83 | static boolean changeColor = false; 84 | static boolean changeColor2 = false; 85 | static boolean selectedColor = false;//在色彩范围栏中选择颜色 86 | 87 | JColorChooser colorChooser = new JColorChooser(Color.black); 88 | 89 | static int deltaColoring = 15;//涂色的色彩rgb接受差值 90 | JSlider jDeltaColor = new JSlider(); 91 | JLabel jDeltaColorText = new JLabel("15"); 92 | 93 | static int deltaColorHue = 73;//原点色相差值 94 | JSlider jDeltaColorHue = new JSlider(); 95 | JLabel jDeltaColorTextHue = new JLabel("73"); 96 | 97 | JTextArea r1 = new JTextArea(); 98 | JTextArea g1 = new JTextArea(); 99 | JTextArea b1 = new JTextArea(); 100 | JTextArea r2 = new JTextArea(); 101 | JTextArea g2 = new JTextArea(); 102 | JTextArea b2 = new JTextArea(); 103 | JTextArea rg1 = new JTextArea(); 104 | JTextArea gb1 = new JTextArea(); 105 | JTextArea rg2 = new JTextArea(); 106 | JTextArea gb2 = new JTextArea(); 107 | private JComboBox jLimitColorRange = new JComboBox(new String[]{"不限制色域", "使用处理2的限制色域"}); 108 | static int operationCnt = 0; 109 | 110 | private JComboBox jParallaxesChooser = new JComboBox(new String[]{"替换", "叠加", "消除【黑底】", "曝光【白底】","透明【仅png有效】"}); 111 | private JComboBox jParallaxesPositionChooser = new JComboBox(new String[]{"替换贴图:原点", "替换贴图:点击点为中心"}); 112 | //------------------------------------------------------------------------ 113 | 114 | static long time = 0; 115 | boolean process = false; 116 | boolean pro = false;//generation mode 117 | 118 | String url = ""; 119 | int times = 1; 120 | int cntColor; 121 | private JPanel panelMap = null; 122 | private JPanel panel = null; 123 | private JPanel panel1 = null; 124 | private BufferedImage img = null; 125 | private BufferedImage img1 = null; 126 | private BufferedImage imgMap = null; 127 | 128 | JTextArea jDelta = new JTextArea(); 129 | JTextArea jAbs = new JTextArea(); 130 | JTextArea jRemoveBlackPixel = new JTextArea(); 131 | JTextArea jRemoveBlackPixel2 = new JTextArea(); 132 | JTextArea jDontProcessColorIfNumLessThan = new JTextArea(); 133 | 134 | JButton lastButton = new JButton("<"); 135 | JButton nextButton = new JButton(">"); 136 | 137 | JButton help = new JButton("帮助"); 138 | JButton Cal = new JButton("生成"); 139 | JButton Cal1 = new JButton("预览"); 140 | JButton load = new JButton("读取图片"); 141 | JButton loadMap = new JButton("读取贴图"); 142 | JButton change = new JButton("转换图片"); 143 | JButton change1 = new JButton("重新加载"); 144 | JButton saveButton = new JButton("保存【.png】"); 145 | JButton ctrlZ = new JButton("撤销"); 146 | JButton reSetColor = new JButton("重置"); 147 | 148 | JLabel nowNumText = new JLabel("1"); 149 | 150 | private final JTabbedPane tabbedPane = new JTabbedPane(); 151 | String urlNow; 152 | 153 | public color2() { 154 | 155 | initComponent(); 156 | this.setVisible(true); 157 | this.setBackground(new Color(0, 0, 100)); 158 | Runner1 r1 = new Runner1(); 159 | Thread t = new Thread(r1); 160 | t.start(); 161 | setFocusable(true); 162 | 163 | this.addMouseListener(new MouseAdapter() { 164 | 165 | boolean mousePress = false; 166 | 167 | @Override 168 | public void mouseClicked(MouseEvent e) { 169 | 170 | if (e.getButton() == 1) {//左键 171 | mouseX = e.getX(); 172 | mouseY = e.getY(); 173 | if (tabbedPane2ColorMod.getSelectedIndex() == 0 && tabbedPane.getSelectedIndex() == 1 && img != null && mouseX > 29 && mouseX < 990 && mouseY > 59 && mouseY < 596) { 174 | 175 | imgX = (int) (img.getWidth() / 2 + (mouseX - (990 + 29) / 2) / (percentIMG)); 176 | imgY = (int) (img.getHeight() / 2 + (mouseY - ((596 + 59)) / 2) / (percentIMG)); 177 | if (imgX > 0 && imgY > 0 && imgX < img.getWidth() && imgY < img.getHeight()) 178 | changeColor = true; 179 | } 180 | if (tabbedPane2ColorMod.getSelectedIndex() == 1 && tabbedPane.getSelectedIndex() == 1 && img != null && mouseX > 29 && mouseX < 990 && mouseY > 59 && mouseY < 596) { 181 | imgX = (int) (img.getWidth() / 2 + (mouseX - (990 + 29) / 2) / (percentIMG)); 182 | imgY = (int) (img.getHeight() / 2 + (mouseY - ((596 + 59)) / 2) / (percentIMG)); 183 | if (imgX > 0 && imgY > 0 && imgX < img.getWidth() && imgY < img.getHeight()) 184 | selectedColor = true; 185 | } 186 | } 187 | if (e.getButton() == 3) { 188 | mouseX = e.getX(); 189 | mouseY = e.getY(); 190 | if (tabbedPane2ColorMod.getSelectedIndex() == 0 && tabbedPane.getSelectedIndex() == 1 && img != null && mouseX > 29 && mouseX < 990 && mouseY > 59 && mouseY < 596) { 191 | 192 | imgX = (int) (img.getWidth() / 2 + (mouseX - (990 + 29) / 2) / (percentIMG)); 193 | imgY = (int) (img.getHeight() / 2 + (mouseY - ((596 + 59)) / 2) / (percentIMG)); 194 | if (imgX > 0 && imgY > 0 && imgX < img.getWidth() && imgY < img.getHeight()) 195 | changeColor2 = true; 196 | } 197 | }//右键 198 | } 199 | 200 | 201 | @Override 202 | public void mousePressed(MouseEvent e) { 203 | mousePress = true; 204 | } 205 | 206 | @Override 207 | public void mouseReleased(MouseEvent e) { 208 | mousePress = false; 209 | changeColor = false; 210 | } 211 | 212 | 213 | }); 214 | 215 | 216 | addKeyListener(new KeyAdapter() { 217 | @Override 218 | public void keyPressed(KeyEvent e) { 219 | 220 | //System.out.println(e.getKeyCode()); 221 | int code = e.getKeyCode(); 222 | if (code == KeyEvent.VK_LEFT) lastPicture(); 223 | if (code == KeyEvent.VK_RIGHT) nextPicture(); 224 | } 225 | }); 226 | 227 | 228 | } 229 | void helpButton(){ 230 | JOptionPane.showMessageDialog(null, "1.《自动描线绘图》功能部分主要参数为“黑边差值(决定黑边的厚度)”和“色泽差值(决定色块的大小,越小越真实)”如果生成出的图片不好看可以改这两个参数\n" + 231 | "2.《二次元魔幻变天》功能可以实现 批量改发色/天空等等有明确边界的地方,也可以修改图片透明度、加水印、上色等等\n" 232 | +"3.处理单张图片请按 预览,处理多张图片使用 生成,生成功能在此之前要对图片们统一命名【即全选后点击重命名】\n" 233 | +"4.这个图片处理器主打处理二次元图片,三次元图片处理会由于模糊问题处理不佳,并且尽量选择“尽量二次元的图片”"); 234 | } 235 | /** 236 | * 237 | */ 238 | void Quick() { 239 | if (jQuick.getSelectedIndex() == 1) { 240 | jDontProcessColorIfNumLessThan.setText("0"); 241 | jRemove.setSelectedIndex(1); 242 | } 243 | if (jQuick.getSelectedIndex() == 2) { 244 | jDontProcessColorIfNumLessThan.setText("10"); 245 | jRemove.setSelectedIndex(2); 246 | } 247 | } 248 | 249 | private void clickTry() { 250 | initImg(); 251 | pro = false; 252 | begin(); 253 | } 254 | 255 | private void click() { 256 | pro = true; 257 | begin(); 258 | } 259 | 260 | private void begin() { 261 | try { 262 | deltaColor = Integer.parseInt(jDelta.getText()); 263 | absBlack = Integer.parseInt(jAbs.getText()); 264 | removeBlackPixel = Integer.parseInt(jRemoveBlackPixel.getText()); 265 | removeBlackPixel2 = Integer.parseInt(jRemoveBlackPixel2.getText()); 266 | notProcessColorIfNumLessThan = Integer.parseInt(jDontProcessColorIfNumLessThan.getText()); 267 | } catch (Exception e) { 268 | } 269 | if (jColorful.getSelectedIndex() == 0) { 270 | colorful = false; 271 | } else { 272 | colorful = true; 273 | } 274 | 275 | if (jRemove.getSelectedIndex() == 0) { 276 | removeBlackLast = false; 277 | } 278 | if (jRemove.getSelectedIndex() == 2) { 279 | removeBlackLast = true; 280 | removeForNormal = false; 281 | } 282 | if (jRemove.getSelectedIndex() == 1) { 283 | removeBlackLast = true; 284 | removeForNormal = true; 285 | } 286 | 287 | if (jBlackTwice.getSelectedIndex() == 0) { 288 | black = false; 289 | } 290 | if (jBlackTwice.getSelectedIndex() == 1) { 291 | black = true; 292 | blackTwice = false; 293 | } 294 | if (jBlackTwice.getSelectedIndex() == 2) { 295 | black = true; 296 | blackTwice = true; 297 | } 298 | 299 | 300 | process = true; 301 | 302 | 303 | } 304 | 305 | private void resetRGB() {//重置选择rgb范围 306 | r1.setText("255"); 307 | r2.setText("0"); 308 | g1.setText("255"); 309 | g2.setText("0"); 310 | b1.setText("255"); 311 | b2.setText("0"); 312 | rg1.setText("255"); 313 | rg2.setText("-255"); 314 | gb1.setText("255"); 315 | gb2.setText("-255"); 316 | } 317 | 318 | private void LoadMap() { 319 | String path = System.getProperty("user.dir")+"/parallaxes"; 320 | JFileChooser choose = new JFileChooser(path); 321 | choose.setDialogTitle("Please Choose Picture"); 322 | FileNameExtensionFilter filter = new FileNameExtensionFilter( 323 | "贴图", "jpg","png"); 324 | choose.setFileFilter(filter); 325 | int returnVal = choose.showOpenDialog(null); 326 | if (returnVal == JFileChooser.APPROVE_OPTION) { 327 | String filepath = choose.getSelectedFile().getPath(); 328 | try { 329 | imgMap = ImageIO.read(new File(filepath)); 330 | } catch (IOException e) { 331 | e.printStackTrace(); 332 | } 333 | panelMap.repaint(); 334 | 335 | 336 | } 337 | } 338 | 339 | private void Load() { 340 | String path = System.getProperty("user.dir"); 341 | JFileChooser choose = new JFileChooser(path); 342 | choose.setDialogTitle("请选择图片"); 343 | FileNameExtensionFilter filter = new FileNameExtensionFilter( 344 | "图片", "png","jpg"); 345 | choose.setFileFilter(filter); 346 | int returnVal = choose.showOpenDialog(null); 347 | if (returnVal == JFileChooser.APPROVE_OPTION) { 348 | String filepath = choose.getSelectedFile().getPath(); 349 | urlNow = filepath; 350 | System.out.println(urlNow); 351 | initImg(); 352 | url = filepath.substring(0, filepath.lastIndexOf("(") + 1); 353 | try { 354 | times = Integer.parseInt(filepath.substring(filepath.lastIndexOf("(") + 1, filepath.lastIndexOf(")"))); 355 | nowNumText.setText(String.valueOf(times)); 356 | } catch (Exception e) { 357 | } 358 | panel1.repaint(); 359 | } 360 | } 361 | 362 | private void initComponent() { 363 | 364 | this.setTitle("图片二创软件 by 零殇 [1.软件免费使用,严禁二次售卖 2.使用该软件制作多张图片并发布时,请附上该软件的发布地址【比如b站视频地址】,谢谢]"); 365 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 366 | this.setSize(1640, 1000); 367 | setLayout(null); 368 | 369 | 370 | JPanel panel1st = new JPanel(); 371 | panel1st.setBounds(0, 0, 600, 700); 372 | panel1st.setLayout(null); 373 | JPanel panel2nd = new JPanel(); 374 | panel2nd.setBounds(0, 0, 600, 700); 375 | panel2nd.setLayout(null); 376 | 377 | tabbedPane.addTab("自动描线绘图", null, panel1st, ""); 378 | tabbedPane.addTab("二次元魔幻变天", null, panel2nd, ""); 379 | tabbedPane.setBounds(1000, 200, 600, 700); 380 | 381 | tabbedPane2ColorMod.setBounds(0, 10, 600, 330); 382 | panel2nd.add(tabbedPane2ColorMod); 383 | tabbedPane2ndDown.setBounds(0, 350, 600, 340); 384 | panel2nd.add(tabbedPane2ndDown); 385 | 386 | //2nd上半部分 387 | JPanel panel2ndUp1 = new JPanel(); 388 | panel2ndUp1.setBounds(0, 0, 600, 300); 389 | panel2ndUp1.setLayout(null); 390 | tabbedPane2ColorMod.addTab("计算方式1:单次替换点击周围区域", null, panel2ndUp1, ""); 391 | JPanel panel2ndUp2 = new JPanel(); 392 | panel2ndUp2.setBounds(0, 0, 600, 300); 393 | panel2ndUp2.setLayout(null); 394 | tabbedPane2ColorMod.addTab("计算方式2:一键替换限定颜色区域", null, panel2ndUp2, ""); 395 | 396 | JLabel help2Label = new JLabel("点击图片更改选定区域块的颜色,调节参数可以控制区域大小。远景建议第一条拉满,第二条10左右"); 397 | help2Label.setBounds(10, 30, 600, 30); 398 | panel2ndUp1.add(help2Label); 399 | JLabel help2Label2 = new JLabel("换(头发)颜色建议第一条拉50上下,第二条拉一半;鼠标悬浮在参数上可以查看参数帮助"); 400 | help2Label2.setBounds(10, 60, 600, 30); 401 | panel2ndUp1.add(help2Label2); 402 | JLabel rgb2 = new JLabel(" 点击重置最大化颜色范围,左键点击图片点缩小颜色区域,点击预览看效果"); 403 | rgb2.setBounds(50, 210, 600, 50); 404 | JLabel rgb1 = new JLabel(" (R-G)范围 (G-B)范围"); 405 | rgb1.setBounds(400, 10, 200, 50); 406 | rg1.setText("0"); 407 | rg1.setBounds(400, 50, 70, 50); 408 | rg1.setFont(new Font("", Font.BOLD, 40)); 409 | rg1.setForeground(Color.RED); 410 | rg2.setText("0"); 411 | rg2.setBounds(400, 120, 70, 50); 412 | rg2.setFont(new Font("", Font.BOLD, 40)); 413 | rg2.setForeground(Color.GREEN); 414 | gb1.setText("0"); 415 | gb1.setBounds(500, 50, 70, 50); 416 | gb1.setFont(new Font("", Font.BOLD, 40)); 417 | gb1.setForeground(Color.GREEN); 418 | gb2.setText("0"); 419 | gb2.setBounds(500, 120, 70, 50); 420 | gb2.setFont(new Font("", Font.BOLD, 40)); 421 | gb2.setForeground(Color.blue); 422 | 423 | r1.setText("0"); 424 | r1.setBounds(50, 50, 70, 50); 425 | r1.setFont(new Font("", Font.BOLD, 40)); 426 | r1.setForeground(Color.RED); 427 | r2.setText("0"); 428 | r2.setBounds(50, 120, 70, 50); 429 | r2.setFont(new Font("", Font.BOLD, 40)); 430 | r2.setForeground(Color.RED); 431 | g1.setText("0"); 432 | g1.setBounds(150, 50, 70, 50); 433 | g1.setFont(new Font("", Font.BOLD, 40)); 434 | g1.setForeground(Color.GREEN); 435 | g2.setText("0"); 436 | g2.setBounds(150, 120, 70, 50); 437 | g2.setFont(new Font("", Font.BOLD, 40)); 438 | g2.setForeground(Color.GREEN); 439 | b1.setText("0"); 440 | b1.setBounds(250, 50, 70, 50); 441 | b1.setFont(new Font("", Font.BOLD, 40)); 442 | b1.setForeground(Color.BLUE); 443 | b2.setText("0"); 444 | b2.setBounds(250, 120, 70, 50); 445 | b2.setFont(new Font("", Font.BOLD, 40)); 446 | b2.setForeground(Color.BLUE); 447 | panel2ndUp2.add(r1); 448 | panel2ndUp2.add(r2); 449 | panel2ndUp2.add(g1); 450 | panel2ndUp2.add(g2); 451 | panel2ndUp2.add(b1); 452 | panel2ndUp2.add(b2); 453 | panel2ndUp2.add(gb1); 454 | panel2ndUp2.add(gb2); 455 | panel2ndUp2.add(rg1); 456 | panel2ndUp2.add(rg2); 457 | panel2ndUp2.add(rgb1); 458 | panel2ndUp2.add(rgb2); 459 | reSetColor.setBounds(20, 3, 90, 37); 460 | reSetColor.setFont(new Font("", Font.BOLD, 19)); 461 | reSetColor.addActionListener((e) -> resetRGB()); 462 | panel2ndUp2.add(reSetColor); 463 | 464 | //2nd下半部分 465 | JPanel panel2nd1 = new JPanel(); 466 | panel2nd1.setBounds(0, 0, 600, 300); 467 | panel2nd1.setLayout(null); 468 | tabbedPane2ndDown.addTab("模式1:用颜色替换", null, panel2nd1, ""); 469 | JPanel panel2nd2 = new JPanel(); 470 | panel2nd2.setBounds(0, 0, 600, 300); 471 | panel2nd2.setLayout(null); 472 | tabbedPane2ndDown.addTab("模式2:用贴图替换", null, panel2nd2, ""); 473 | loadMap.setBounds(20, 20, 140, 40); 474 | loadMap.setFont(new Font("", Font.BOLD, 19)); 475 | loadMap.addActionListener((e) -> LoadMap()); 476 | panel2nd2.add(loadMap); 477 | 478 | 479 | panelMap = new JPanel() { 480 | @Override 481 | protected void paintComponent(Graphics g) { 482 | super.paintComponent(g); 483 | Graphics2D g2 = (Graphics2D) g; 484 | g2.drawImage(imgMap, 0, 0, this.getWidth(), this.getHeight(), null); 485 | } 486 | }; 487 | panelMap.setBounds(280, 25, 250, 250); 488 | panelMap.setBackground(new Color(255, 224, 224)); 489 | panel2nd2.add(panelMap); 490 | 491 | 492 | colorChooser.setBounds(20, 0, 560, 300); 493 | panel2nd1.add(colorChooser); 494 | 495 | 496 | jColorful.setBounds(400, 500, 150, 40); 497 | jColorful.setSelectedIndex(0); 498 | panel1st.add(jColorful); 499 | 500 | jBlackTwice.setBounds(400, 100, 120, 40); 501 | jBlackTwice.setSelectedIndex(1); 502 | panel1st.add(jBlackTwice); 503 | 504 | jQuick.addActionListener((e -> Quick())); 505 | jQuick.setBounds(200, 500, 150, 40); 506 | jQuick.setSelectedIndex(0); 507 | panel1st.add(jQuick); 508 | 509 | jLimitColorRange.setBounds(20, 240, 150, 40); 510 | jLimitColorRange.setSelectedIndex(0); 511 | panel2ndUp1.add(jLimitColorRange); 512 | 513 | jParallaxesChooser.setBounds(20, 100, 150, 40); 514 | jParallaxesChooser.setSelectedIndex(0); 515 | panel2nd2.add(jParallaxesChooser); 516 | jParallaxesPositionChooser.setBounds(20, 200, 150, 40); 517 | jParallaxesPositionChooser.setSelectedIndex(0); 518 | panel2nd2.add(jParallaxesPositionChooser); 519 | 520 | jRemove.setBounds(400, 400, 150, 40); 521 | jRemove.setSelectedIndex(1); 522 | panel1st.add(jRemove); 523 | JLabel jRemoveText = new JLabel("最后处理黑色描边的模式"); 524 | jRemoveText.setBounds(40, 400, 380, 50); 525 | jRemoveText.setFont(new Font("", Font.BOLD, 25)); 526 | panel1st.add(jRemoveText); 527 | 528 | jSpeed.addChangeListener((e) -> speedChange()); 529 | jSpeed.setMaximum(75); 530 | jSpeed.setMinimum(0); 531 | jSpeed.setBounds(170, 30, 400, 40); 532 | panel1st.add(jSpeed); 533 | JLabel jSpeedText = new JLabel("处理速度"); 534 | jSpeedText.setBounds(40, 25, 120, 50); 535 | jSpeedText.setFont(new Font("", Font.BOLD, 25)); 536 | panel1st.add(jSpeedText); 537 | 538 | jDeltaColorHue.addChangeListener((e) -> colorDeltaChange()); 539 | jDeltaColorHue.setMaximum(200); 540 | jDeltaColorHue.setMinimum(1); 541 | jDeltaColorHue.setValue(60); 542 | jDeltaColorHue.setBounds(230, 130, 340, 40); 543 | panel2ndUp1.add(jDeltaColorHue); 544 | JLabel jDeltaColorTextHue2 = new JLabel("原点色相差距"); 545 | jDeltaColorTextHue2.setToolTipText("当前点和原点的(|r-g|+|g-b|)的绝对差值,用于杜绝和原点色差多大的地方,数值越小范围越小"); 546 | jDeltaColorTextHue2.setBounds(40, 125, 180, 50); 547 | jDeltaColorTextHue2.setFont(new Font("", Font.BOLD, 25)); 548 | panel2ndUp1.add(jDeltaColorTextHue2); 549 | jDeltaColorTextHue.setBounds(80, 100, 60, 50); 550 | jDeltaColorTextHue.setFont(new Font("", Font.BOLD, 15)); 551 | panel2ndUp1.add(jDeltaColorTextHue); 552 | 553 | 554 | jDeltaColor.addChangeListener((e) -> colorDeltaChange()); 555 | jDeltaColor.setMaximum(75); 556 | jDeltaColor.setMinimum(1); 557 | jDeltaColor.setValue(26); 558 | jDeltaColor.setBounds(230, 180, 340, 40); 559 | panel2ndUp1.add(jDeltaColor); 560 | JLabel jDeltaColorText2 = new JLabel("相邻色彩差距"); 561 | jDeltaColorText2.setToolTipText("当前点和周围点的 r g b 的绝对差值之和,用于寻找边缘,数值越小范围越小"); 562 | jDeltaColorText2.setBounds(40, 175, 180, 50); 563 | jDeltaColorText2.setFont(new Font("", Font.BOLD, 25)); 564 | panel2ndUp1.add(jDeltaColorText2); 565 | jDeltaColorText.setBounds(80, 150, 60, 50); 566 | jDeltaColorText.setFont(new Font("", Font.BOLD, 15)); 567 | panel2ndUp1.add(jDeltaColorText); 568 | 569 | 570 | jSpeedText2.setBounds(80, 0, 60, 50); 571 | jSpeedText2.setFont(new Font("", Font.BOLD, 15)); 572 | panel1st.add(jSpeedText2); 573 | 574 | 575 | panel1 = new JPanel() { 576 | @Override 577 | protected void paintComponent(Graphics g) { 578 | super.paintComponent(g); 579 | Graphics2D g2 = (Graphics2D) g; 580 | if (img1 != null) { 581 | double percent = Math.min(1.0 * this.getWidth() / img1.getWidth(), 1.0 * this.getHeight() / img1.getHeight()); 582 | g2.drawImage(img1, (int) (img1.getWidth() * (-percent / 2) + this.getWidth() / 2), (int) (img1.getHeight() * (-percent / 2) + this.getHeight() / 2), (int) (img1.getWidth() * (percent)), (int) (img1.getHeight() * (percent)), null); 583 | 584 | } 585 | } 586 | }; 587 | panel1.setBounds(80, 580, 580, 320); 588 | panel1.setBackground(new Color(224, 224, 255)); 589 | 590 | this.add(panel1); 591 | panel = new JPanel() { 592 | @Override 593 | protected void paintComponent(Graphics g) { 594 | super.paintComponent(g); 595 | Graphics2D g2 = (Graphics2D) g; 596 | if (img != null) { 597 | double percent = Math.min(1.0 * this.getWidth() / img.getWidth(), 1.0 * this.getHeight() / img.getHeight()); 598 | percentIMG = percent; 599 | g2.drawImage(img, (int) (img.getWidth() * (-percent / 2) + this.getWidth() / 2), (int) (img.getHeight() * (-percent / 2) + this.getHeight() / 2), (int) (img.getWidth() * (percent)), (int) (img.getHeight() * (percent)), null); 600 | } 601 | } 602 | }; 603 | 604 | panel.setBounds(20, 20, 960, 540); 605 | panel.setBackground(new Color(224, 255, 224)); 606 | this.add(panel); 607 | load.setBounds(1100, 70, 120, 60); 608 | load.setFont(new Font("", Font.BOLD, 20)); 609 | load.addActionListener((e) -> Load()); 610 | 611 | change.setBounds(720, 580, 120, 50); 612 | change.setFont(new Font("", Font.BOLD, 20)); 613 | change.addActionListener((e) -> Change()); 614 | this.add(change); 615 | change1.setBounds(860, 580, 120, 50); 616 | change1.setFont(new Font("", Font.BOLD, 20)); 617 | change1.addActionListener((e) -> Change1()); 618 | this.add(change1); 619 | 620 | 621 | saveButton.setBounds(720, 680, 130, 50); 622 | saveButton.setFont(new Font("", Font.BOLD, 15)); 623 | saveButton.addActionListener((e) -> savePic()); 624 | this.add(saveButton); 625 | 626 | ctrlZ.setBounds(860, 680, 120, 50); 627 | ctrlZ.setFont(new Font("", Font.BOLD, 20)); 628 | ctrlZ.addActionListener((e) -> CtrlZ()); 629 | this.add(ctrlZ); 630 | 631 | Cal.setBounds(1250, 70, 130, 60); 632 | Cal.setFont(new Font("", Font.BOLD, 20)); 633 | Cal.addActionListener((e) -> click()); 634 | Cal1.setBounds(1420, 70, 120, 60); 635 | Cal1.setFont(new Font("", Font.BOLD, 20)); 636 | Cal1.addActionListener((e) -> clickTry()); 637 | 638 | help.setBounds(10, 905, 86, 40); 639 | help.setFont(new Font("", Font.BOLD, 20)); 640 | help.addActionListener((e) -> helpButton()); 641 | this.add(help); 642 | 643 | nowNumText.setBounds(360, 905, 46, 40); 644 | nowNumText.setFont(new Font("", Font.BOLD, 20)); 645 | this.add(nowNumText); 646 | lastButton.setBounds(300, 905, 46, 40); 647 | lastButton.setFont(new Font("", Font.BOLD, 20)); 648 | lastButton.addActionListener((e) -> lastPicture()); 649 | this.add(lastButton); 650 | nextButton.setBounds(400, 905, 46, 40); 651 | nextButton.setFont(new Font("", Font.BOLD, 20)); 652 | nextButton.addActionListener((e) -> nextPicture()); 653 | this.add(nextButton); 654 | 655 | 656 | jAbs.setText("25"); 657 | jAbs.setBounds(150, 100, 70, 40); 658 | jAbs.setFont(new Font("", Font.BOLD, 25)); 659 | jAbs.setForeground(Color.BLACK); 660 | panel1st.add(jAbs); 661 | JLabel jAbsText = new JLabel("黑边差值"); 662 | jAbsText.setBounds(40, 100, 90, 50); 663 | jAbsText.setFont(new Font("", Font.BOLD, 20)); 664 | panel1st.add(jAbsText); 665 | 666 | jDelta.setText("7"); 667 | jDelta.setBounds(150, 160, 70, 40); 668 | jDelta.setFont(new Font("", Font.BOLD, 25)); 669 | jDelta.setForeground(Color.PINK); 670 | panel1st.add(jDelta); 671 | JLabel jDeltaText = new JLabel("色泽差值"); 672 | jDeltaText.setBounds(40, 160, 90, 50); 673 | jDeltaText.setFont(new Font("", Font.BOLD, 20)); 674 | panel1st.add(jDeltaText); 675 | 676 | jDontProcessColorIfNumLessThan.setText("0"); 677 | jDontProcessColorIfNumLessThan.setBounds(250, 240, 70, 40); 678 | jDontProcessColorIfNumLessThan.setFont(new Font("", Font.BOLD, 25)); 679 | jDontProcessColorIfNumLessThan.setForeground(Color.red); 680 | panel1st.add(jDontProcessColorIfNumLessThan); 681 | JLabel jDontProcessColorIfNumLessThanText = new JLabel("不处理少于x像素的色块"); 682 | jDontProcessColorIfNumLessThanText.setBounds(40, 240, 210, 50); 683 | jDontProcessColorIfNumLessThanText.setFont(new Font("", Font.BOLD, 17)); 684 | panel1st.add(jDontProcessColorIfNumLessThanText); 685 | 686 | jRemoveBlackPixel.setText("300"); 687 | jRemoveBlackPixel.setBounds(200, 320, 70, 40); 688 | jRemoveBlackPixel.setFont(new Font("", Font.BOLD, 30)); 689 | jRemoveBlackPixel.setForeground(Color.black); 690 | panel1st.add(jRemoveBlackPixel); 691 | JLabel jRemoveBlackPixelText = new JLabel("不画少于x像素的黑边"); 692 | jRemoveBlackPixelText.setBounds(10, 320, 210, 50); 693 | jRemoveBlackPixelText.setFont(new Font("", Font.BOLD, 17)); 694 | panel1st.add(jRemoveBlackPixelText); 695 | 696 | jRemoveBlackPixel2.setText("60"); 697 | jRemoveBlackPixel2.setBounds(490, 320, 70, 40); 698 | jRemoveBlackPixel2.setFont(new Font("", Font.BOLD, 30)); 699 | jRemoveBlackPixel2.setForeground(Color.black); 700 | panel1st.add(jRemoveBlackPixel2); 701 | JLabel jRemoveBlackPixelText2 = new JLabel("移除大个黑色块的强度"); 702 | jRemoveBlackPixelText2.setBounds(320, 320, 160, 50); 703 | jRemoveBlackPixelText2.setFont(new Font("", Font.BOLD, 15)); 704 | panel1st.add(jRemoveBlackPixelText2); 705 | 706 | this.add(tabbedPane); 707 | this.add(Cal); 708 | this.add(Cal1); 709 | this.add(load); 710 | } 711 | 712 | private void speedChange() { 713 | speed = 0.1 * Math.pow(1.1, jSpeed.getValue()); 714 | jSpeedText2.setText("x" + (int) (speed * 10)); 715 | if (speed > 100) { 716 | jSpeedText2.setText("Max"); 717 | } 718 | } 719 | 720 | private void colorDeltaChange() { 721 | deltaColoring = 1 + jDeltaColor.getValue() * jDeltaColor.getValue() / 50; 722 | jDeltaColorText.setText("" + deltaColoring); 723 | 724 | deltaColorHue = 1 + jDeltaColorHue.getValue() * jDeltaColorHue.getValue() / 50; 725 | jDeltaColorTextHue.setText("" + deltaColorHue); 726 | } 727 | 728 | private void Change() { 729 | 730 | BufferedImage img3 = img1; 731 | img1 = img; 732 | img = img3; 733 | panel.repaint(); 734 | panel1.repaint(); 735 | } 736 | 737 | private void Change1() { 738 | File file = new File(urlNow); 739 | try { 740 | img = ImageIO.read(file); 741 | img1 = ImageIO.read(file); 742 | } catch (IOException ignored) { 743 | } 744 | panel.repaint(); 745 | panel1.repaint(); 746 | } 747 | 748 | private void CtrlZ() { 749 | if (operationCnt == 0) return; 750 | operationCnt--; 751 | String s = System.getProperty("user.dir") + "/save/data/" + operationCnt + ".jpg"; 752 | File file = new File(s); 753 | try { 754 | img = ImageIO.read(file); 755 | } catch (IOException e) { 756 | e.printStackTrace(); 757 | } 758 | panel.repaint(); 759 | } 760 | 761 | static boolean stop = false; 762 | 763 | private void initImg() { 764 | File file = new File(urlNow); 765 | try { 766 | img = ImageIO.read(file); 767 | img1 = ImageIO.read(file); 768 | panel1.repaint(); 769 | panel.repaint(); 770 | } catch (IOException e) { 771 | if (times > 1) 772 | times--; 773 | JOptionPane.showMessageDialog(null, "已经是最后一张图片了"); 774 | stop = true; 775 | 776 | } 777 | } 778 | 779 | private void copyPic() { 780 | 781 | try { 782 | ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/save/data/" + operationCnt + ".jpg")); 783 | ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/save/last" + ".jpg")); 784 | 785 | } catch (IOException e) { 786 | e.printStackTrace(); 787 | } 788 | operationCnt++; 789 | } 790 | 791 | private void savePic() { 792 | LocalDateTime currentTime = LocalDateTime.now(); 793 | 794 | long date = currentTime.getYear() * 10000000000L + currentTime.getDayOfMonth() * 1000000 + currentTime.getMonthValue() * 100000000L + currentTime.getHour() * 10000 + currentTime.getMinute() * 100 + currentTime.getSecond(); 795 | try { 796 | //ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/save/" + (date % 1000000) + ".jpg")); 797 | ImageIO.write(img, "PNG", new FileOutputStream(System.getProperty("user.dir") + "/save/" + date + ".png")); 798 | JOptionPane.showMessageDialog(null, "已经保存至save文件夹"); 799 | } catch (IOException e) { 800 | e.printStackTrace(); 801 | } 802 | 803 | } 804 | 805 | void lastPicture() { 806 | if (times <= 1) { 807 | JOptionPane.showMessageDialog(null, "这已经是第一张图片"); 808 | return; 809 | } 810 | times--; 811 | urlNow = url + times + ").jpg"; 812 | initImg(); 813 | nowNumText.setText(String.valueOf(times)); 814 | operationCnt = 0; 815 | } 816 | 817 | void nextPicture() { 818 | if (operationCnt > 0) { 819 | File file = new File(url.substring(0, url.lastIndexOf("\\")) + "/autoSave"); 820 | if (!file.exists()) {//如果文件夹不存在 821 | file.mkdir();//创建文件夹 822 | } 823 | try { 824 | //ImageIO.write(img, "JPEG", new FileOutputStream(url.substring(0, url.lastIndexOf("\\")) + "/autoSave/(" + times + ").jpg")); 825 | ImageIO.write(img, "PNG", new FileOutputStream(url.substring(0, url.lastIndexOf("\\")) + "/autoSave/(" + times + ").png")); 826 | 827 | } catch (IOException e) { 828 | e.printStackTrace(); 829 | } 830 | } 831 | times++; 832 | urlNow = url + times + ").jpg"; 833 | initImg(); 834 | nowNumText.setText(String.valueOf(times)); 835 | operationCnt = 0; 836 | 837 | } 838 | 839 | 840 | /** 841 | * 处理图片 842 | */ 843 | 844 | 845 | public static void main(String[] args) { 846 | LocalDateTime currentTime = LocalDateTime.now(); 847 | time = currentTime.getYear() * 10000000000L + currentTime.getDayOfMonth() * 1000000 + currentTime.getMonthValue() * 100000000L + currentTime.getHour() * 10000 + currentTime.getMinute() * 100 + currentTime.getSecond(); 848 | 849 | 850 | File file = new File(System.getProperty("user.dir") + "/output"); 851 | if (!file.exists()) {//如果文件夹不存在 852 | file.mkdir();//创建文件夹 853 | } 854 | file = new File(System.getProperty("user.dir") + "/save"); 855 | if (!file.exists()) {//如果文件夹不存在 856 | file.mkdir();//创建文件夹 857 | } 858 | file = new File(System.getProperty("user.dir") + "/save/data"); 859 | if (!file.exists()) {//如果文件夹不存在 860 | file.mkdir();//创建文件夹 861 | } 862 | new color2(); 863 | } 864 | 865 | 866 | class Runner1 implements Runnable { 867 | 868 | int cnt = 0; 869 | 870 | @Override 871 | public void run() { 872 | while (true) { 873 | try { 874 | Thread.sleep(20); 875 | } catch (InterruptedException e) { 876 | e.printStackTrace(); 877 | } 878 | if (selectedColor) { 879 | colorSelected(imgX, imgY); 880 | selectedColor = false; 881 | } 882 | if (changeColor) { 883 | copyPic(); 884 | processImgChangeColor(imgX, imgY, false); 885 | changeColor = false; 886 | } 887 | if (changeColor2) { 888 | copyPic(); 889 | processImgChangeColor(imgX, imgY, true); 890 | changeColor2 = false; 891 | } 892 | if (process) { 893 | if (!pro) 894 | processImg(); 895 | else { 896 | for (; times < 10000; times++) { 897 | nowNumText.setText(String.valueOf(times)); 898 | urlNow = url + times + ").jpg"; 899 | initImg(); 900 | System.out.println(url + times + ").jpg"); 901 | processImg(); 902 | if (stop) break; 903 | 904 | } 905 | } 906 | 907 | 908 | stop = false; 909 | process = false; 910 | } 911 | } 912 | } 913 | 914 | //第二页处理2 选颜色功能 915 | private void colorSelected(int x, int y) { 916 | Color color = new Color(img.getRGB(x, y)); 917 | int rMax = Math.min(255, color.getRed() + 5); 918 | int rMin = Math.max(0, color.getRed() - 5); 919 | int gMax = Math.min(255, color.getGreen() + 5); 920 | int gMin = Math.max(0, color.getGreen() - 5); 921 | int bMax = Math.min(255, color.getBlue() + 5); 922 | int bMin = Math.max(0, color.getBlue() - 5); 923 | r1.setText(String.valueOf(Math.min(Integer.parseInt(r1.getText()), rMin))); 924 | r2.setText(String.valueOf(Math.max(Integer.parseInt(r2.getText()), rMax))); 925 | g1.setText(String.valueOf(Math.min(Integer.parseInt(g1.getText()), gMin))); 926 | g2.setText(String.valueOf(Math.max(Integer.parseInt(g2.getText()), gMax))); 927 | b1.setText(String.valueOf(Math.min(Integer.parseInt(b1.getText()), bMin))); 928 | b2.setText(String.valueOf(Math.max(Integer.parseInt(b2.getText()), bMax))); 929 | rg1.setText(String.valueOf(Math.min(Integer.parseInt(rg1.getText()), rMin - gMax))); 930 | rg2.setText(String.valueOf(Math.max(Integer.parseInt(rg2.getText()), rMax - gMin))); 931 | gb1.setText(String.valueOf(Math.min(Integer.parseInt(gb1.getText()), gMin - bMax))); 932 | gb2.setText(String.valueOf(Math.max(Integer.parseInt(gb2.getText()), gMax - bMin))); 933 | } 934 | 935 | //第二页处理1 改变颜色 936 | private void processImgChangeColor(int x, int y, boolean Mode) { 937 | 938 | 939 | if (!Mode) { 940 | Queue q1 = new LinkedList<>(); 941 | q1.add(x * 10000 + y); 942 | pro3Color(q1, colorChooser.getColor(), new Color(img.getRGB(x, y)), tabbedPane2ndDown.getSelectedIndex() != 0, false); 943 | } else { 944 | Queue q1 = new LinkedList<>(); 945 | for (int i = -4; i < 4; i++) { 946 | for (int j = -4; j < 4; j++) { 947 | q1.add(Math.max(0, (x + i)) * 10000 + Math.max(0, y + j)); 948 | } 949 | } 950 | 951 | pro3Color(q1, colorChooser.getColor(), new Color(img.getRGB(x, y)), tabbedPane2ndDown.getSelectedIndex() != 0, true); 952 | 953 | } 954 | 955 | panel.repaint(); 956 | } 957 | 958 | //第一页处理 基础 959 | private void processImg() { 960 | if (tabbedPane.getSelectedIndex() == 1 && tabbedPane2ColorMod.getSelectedIndex() == 1) { 961 | int r = (Integer.parseInt(r1.getText()) + Integer.parseInt(r2.getText())) / 2; 962 | int g = (Integer.parseInt(g1.getText()) + Integer.parseInt(g2.getText())) / 2; 963 | int b = (Integer.parseInt(b1.getText()) + Integer.parseInt(b2.getText())) / 2; 964 | proColorWithColorRange(colorChooser.getColor(), new Color(r, g, b), tabbedPane2ndDown.getSelectedIndex() != 0); 965 | return; 966 | } 967 | if (img == null) { 968 | System.out.println("错误!无图片"); 969 | return; 970 | } 971 | int data[][][] = new int[img.getWidth()][img.getHeight()][11]; 972 | for (int x = 0; x < img.getWidth(); x++) { 973 | for (int y = 0; y < img.getHeight(); y++) { 974 | data[x][y][0] = 1; 975 | data[x][y][10] = img.getRGB(x, y); 976 | Color color = new Color(255, 255, 255); 977 | img.setRGB(x, y, color.getRGB()); 978 | if (!pro) 979 | panel.repaint(); 980 | } 981 | } 982 | for (int x = 1; x < img.getWidth() - 1; x++) { 983 | for (int y = 1; y < img.getHeight() - 1; y++) { 984 | 985 | double red = (new Color(data[x - 1][y][10]).getRed() + new Color(data[x + 1][y][10]).getRed() - new Color(data[x][y - 1][10]).getRed() 986 | - new Color(data[x][y + 1][10]).getRed() + 0.5 * (new Color(data[x - 1][y - 1][10]).getRed() - new Color(data[x + 1][y + 1][10]).getRed()) 987 | + 0.5 * (new Color(data[x + 1][y - 1][10]).getRed() - new Color(data[x - 1][y + 1][10]).getRed())); 988 | double green = (new Color(data[x - 1][y][10]).getGreen() + new Color(data[x + 1][y][10]).getGreen() - new Color(data[x][y - 1][10]).getGreen() 989 | - new Color(data[x][y + 1][10]).getGreen() + 0.5 * (new Color(data[x - 1][y - 1][10]).getGreen() - new Color(data[x + 1][y + 1][10]).getGreen()) 990 | + 0.5 * (new Color(data[x + 1][y - 1][10]).getGreen() - new Color(data[x - 1][y + 1][10]).getGreen())); 991 | double blue = (new Color(data[x - 1][y][10]).getBlue() + new Color(data[x + 1][y][10]).getBlue() - new Color(data[x][y - 1][10]).getBlue() 992 | - new Color(data[x][y + 1][10]).getBlue() + 0.5 * (new Color(data[x - 1][y - 1][10]).getBlue() - new Color(data[x + 1][y + 1][10]).getBlue()) 993 | + 0.5 * (new Color(data[x + 1][y - 1][10]).getBlue() - new Color(data[x - 1][y + 1][10]).getBlue())); 994 | 995 | double delta1 = 996 | (new Color(data[x - 1][y][10]).getBlue() + new Color(data[x + 1][y][10]).getBlue() + new Color(data[x][y - 1][10]).getBlue() + new Color(data[x][y + 1][10]).getBlue()) - 997 | (new Color(data[x - 1][y][10]).getRed() + new Color(data[x + 1][y][10]).getRed() + new Color(data[x][y - 1][10]).getRed() + new Color(data[x][y + 1][10]).getRed()); 998 | double delta2 = 999 | (new Color(data[x - 1][y][10]).getBlue() + new Color(data[x + 1][y][10]).getBlue() + new Color(data[x][y - 1][10]).getBlue() + new Color(data[x][y + 1][10]).getBlue()) - 1000 | (new Color(data[x - 1][y][10]).getGreen() + new Color(data[x + 1][y][10]).getGreen() + new Color(data[x][y - 1][10]).getGreen() + new Color(data[x][y + 1][10]).getGreen()); 1001 | 1002 | 1003 | if (black) 1004 | if (Math.abs(red) + Math.abs(green) + Math.abs(blue) > absBlack) data[x][y][0] = 0;//black 1005 | if (black) 1006 | if (Math.abs(red) + Math.abs(green) + Math.abs(blue) > 2.5 * absBlack) data[x][y][3] = 1;//gray 1007 | 1008 | 1009 | } 1010 | } 1011 | // if(blackTwice) 1012 | for (int y = 1; y < img.getHeight() - 1; y++) { 1013 | for (int x = 1; x < img.getWidth() - 1; x++) { 1014 | if (data[x][y][1] == 0 && data[x][y][0] <= 0) { 1015 | Queue q = new LinkedList<>(); 1016 | q.add(x * 10000 + y); 1017 | proRemove(x, y, data, q, 0); 1018 | } 1019 | } 1020 | } 1021 | for (int y = 1; y < img.getHeight() - 1; y++) { 1022 | for (int x = 1; x < img.getWidth() - 1; x++) { 1023 | if (data[x][y][1] == 0 && data[x][y][0] <= 0) { 1024 | Queue q = new LinkedList<>(); 1025 | q.add(x * 10000 + y); 1026 | proRemove(x, y, data, q, 1); 1027 | } 1028 | } 1029 | } 1030 | //消除小黑 1031 | 1032 | if (black) {//黑色线描绘 1033 | if (blackTwice) 1034 | for (int y = 1; y < img.getHeight() - 1; y++) { 1035 | for (int x = 1; x < img.getWidth() - 1; x++) { 1036 | if (data[x][y][1] <= 0) { 1037 | Stack q = new Stack<>(); 1038 | q.add(x * 10000 + y); 1039 | pro(data, q, 1); 1040 | } 1041 | } 1042 | } 1043 | for (int y = 1; y < img.getHeight() - 1; y++) { 1044 | for (int x = 1; x < img.getWidth() - 1; x++) { 1045 | if (data[x][y][1] <= 0) { 1046 | Stack q = new Stack<>(); 1047 | q.add(x * 10000 + y); 1048 | pro(data, q, 0); 1049 | } 1050 | } 1051 | } 1052 | } 1053 | if (jColorful.getSelectedIndex() != 2) 1054 | for (int y = 1; y < img.getHeight() - 1; y++) { 1055 | for (int x = 1; x < img.getWidth() - 1; x++) { 1056 | if (data[x][y][1] == 0) { 1057 | Queue q = new LinkedList<>(); 1058 | q.add(x * 10000 + y); 1059 | Color color = new Color(data[x][y][10]); 1060 | 1061 | Color color2 = pro2(data, q, color); 1062 | 1063 | if (colorful) { 1064 | int total = color2.getGreen() + color2.getBlue() + color2.getRed(); 1065 | int min, max; 1066 | min = Math.max(0, total - 255 * 2); 1067 | max = Math.min(255, 2 * total / 3); 1068 | int red = (int) (min + (max - min) * Math.random()); 1069 | total -= red; 1070 | min = Math.max(0, total - 255); 1071 | max = Math.min(255, total); 1072 | int green = (int) (min + (max - min) * Math.random()); 1073 | color2 = new Color(red, green, total - green); 1074 | } 1075 | 1076 | if (cntColor >= notProcessColorIfNumLessThan) { 1077 | Queue q1 = new LinkedList<>(); 1078 | q1.add(x * 10000 + y); 1079 | pro3(data, q1, color2); 1080 | if (cnt > speed * 30) { 1081 | if (!paintNotPause) 1082 | update(); 1083 | } 1084 | } 1085 | } 1086 | } 1087 | } 1088 | 1089 | 1090 | //remove black 1091 | if (removeBlackLast) if (jColorful.getSelectedIndex() != 2) 1092 | for (int y = 1; y < img.getHeight() - 1; y++) { 1093 | for (int x = 1; x < img.getWidth() - 1; x++) { 1094 | if (data[x][y][9] != 0) { 1095 | img.setRGB(x, y, data[x][y][9]); 1096 | } 1097 | 1098 | if (removeBlackLast && data[x][y][1] == 1 || data[x][y][1] == 4) { 1099 | Color color; 1100 | if (data[x][y][1] == 4 || !removeForNormal) { 1101 | int x1 = x, y1 = y; 1102 | int w = img.getWidth(), h = img.getHeight(); 1103 | boolean br = false; 1104 | for (int i = 1; i < 50; i += 2) { 1105 | for (int j = 0; j <= i; j++) { 1106 | x1++; 1107 | if (data[(w + x1) % w][(h + y1) % h][1] == 2) { 1108 | br = true; 1109 | break; 1110 | } 1111 | } 1112 | if (br) break; 1113 | for (int j = 0; j <= i; j++) { 1114 | y1++; 1115 | if (data[(w + x1) % w][(h + y1) % h][1] == 2) { 1116 | br = true; 1117 | break; 1118 | } 1119 | } 1120 | if (br) break; 1121 | for (int j = 0; j <= i + 1; j++) { 1122 | x1--; 1123 | if (data[(w + x1) % w][(h + y1) % h][1] == 2) { 1124 | br = true; 1125 | break; 1126 | } 1127 | } 1128 | if (br) break; 1129 | for (int j = 0; j <= i + 1; j++) { 1130 | y1--; 1131 | if (data[(w + x1) % w][(h + y1) % h][1] == 2) { 1132 | br = true; 1133 | break; 1134 | } 1135 | } 1136 | if (br) break; 1137 | } 1138 | color = new Color(data[(w + x1) % w][(h + y1) % h][10]); 1139 | } else color = new Color(data[x][y][10]); 1140 | img.setRGB(x, y, color.getRGB()); 1141 | cnt++; 1142 | if (cnt > speed * 20) { 1143 | if (!paintNotPause) 1144 | update(); 1145 | cnt -= speed * 20; 1146 | } 1147 | } 1148 | } 1149 | } 1150 | 1151 | panel.repaint(); 1152 | 1153 | File file = new File(System.getProperty("user.dir") + "/output/" + time); 1154 | if (!file.exists()) {//如果文件夹不存在 1155 | file.mkdir();//创建文件夹 1156 | } 1157 | if (!pro) { 1158 | try { 1159 | ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/" + time + "/" + (int) (Math.random() * 10000) + ".jpg")); 1160 | } catch (IOException e) { 1161 | e.printStackTrace(); 1162 | } 1163 | } else { 1164 | try { 1165 | ImageIO.write(img, "JPEG", new FileOutputStream(System.getProperty("user.dir") + "/output/" + time + "/pic" + times + ".jpg")); 1166 | } catch (IOException e) { 1167 | e.printStackTrace(); 1168 | } 1169 | } 1170 | } 1171 | 1172 | void pro(int data[][][], Stack queue, int mode) {//mode 1 第一次灰,0 第二次黑 1173 | while (queue.size() > 0) { 1174 | 1175 | int a = (int) queue.pop(); 1176 | int x = a / 10000; 1177 | int y = a % 10000; 1178 | 1179 | if ((mode == 0 && data[x][y][0] <= 0 && data[x][y][1] <= 0) || (mode == 1 && data[x][y][0] <= 0 && data[x][y][3] == 1)) { 1180 | 1181 | Color color; 1182 | if (mode == 0) 1183 | color = new Color(0, 0, 0); 1184 | else 1185 | color = new Color(160, 160, 160); 1186 | 1187 | img.setRGB(x, y, color.getRGB()); 1188 | 1189 | if (mode == 0) { 1190 | data[x][y][1] = 1; 1191 | data[x][y][0] = 2; 1192 | } 1193 | data[x][y][3] = 0; 1194 | 1195 | 1196 | //周围浅描绘 1197 | if (mode == 0) { 1198 | int delta = 80, delta1 = 0, max = 40; 1199 | 1200 | int x1, y1; 1201 | x1 = (img.getWidth() + x + 1) % img.getWidth(); 1202 | y1 = (img.getHeight() + y) % img.getHeight(); 1203 | int c = new Color(img.getRGB(x1, y1)).getRed(); 1204 | c = Math.max(Math.min(max, c), c - delta); 1205 | img.setRGB(x1, y1, new Color(c, c, c).getRGB()); 1206 | x1 = (img.getWidth() + x - 1) % img.getWidth(); 1207 | y1 = (img.getHeight() + y) % img.getHeight(); 1208 | c = new Color(img.getRGB(x1, y1)).getRed(); 1209 | c = Math.max(Math.min(max, c), c - delta); 1210 | img.setRGB(x1, y1, new Color(c, c, c).getRGB()); 1211 | x1 = (img.getWidth() + x) % img.getWidth(); 1212 | y1 = (img.getHeight() + y + 1) % img.getHeight(); 1213 | c = new Color(img.getRGB(x1, y1)).getRed(); 1214 | c = Math.max(Math.min(max, c), c - delta); 1215 | img.setRGB(x1, y1, new Color(c, c, c).getRGB()); 1216 | x1 = (img.getWidth() + x) % img.getWidth(); 1217 | y1 = (img.getHeight() + y - 1) % img.getHeight(); 1218 | c = new Color(img.getRGB(x1, y1)).getRed(); 1219 | c = Math.max(Math.min(max, c), c - delta); 1220 | img.setRGB(x1, y1, new Color(c, c, c).getRGB()); 1221 | 1222 | 1223 | x1 = (img.getWidth() + x + 2) % img.getWidth(); 1224 | y1 = (img.getHeight() + y) % img.getHeight(); 1225 | c = new Color(img.getRGB(x1, y1)).getRed(); 1226 | c = Math.max(Math.min(max, c), c - delta1); 1227 | img.setRGB(x1, y1, new Color(c, c, c).getRGB()); 1228 | x1 = (img.getWidth() + x - 2) % img.getWidth(); 1229 | y1 = (img.getHeight() + y) % img.getHeight(); 1230 | c = new Color(img.getRGB(x1, y1)).getRed(); 1231 | c = Math.max(Math.min(max, c), c - delta1); 1232 | img.setRGB(x1, y1, new Color(c, c, c).getRGB()); 1233 | x1 = (img.getWidth() + x) % img.getWidth(); 1234 | y1 = (img.getHeight() + y + 2) % img.getHeight(); 1235 | c = new Color(img.getRGB(x1, y1)).getRed(); 1236 | c = Math.max(Math.min(max, c), c - delta1); 1237 | img.setRGB(x1, y1, new Color(c, c, c).getRGB()); 1238 | x1 = (img.getWidth() + x) % img.getWidth(); 1239 | y1 = (img.getHeight() + y - 2) % img.getHeight(); 1240 | c = new Color(img.getRGB(x1, y1)).getRed(); 1241 | c = Math.max(Math.min(max, c), c - delta1); 1242 | img.setRGB(x1, y1, new Color(c, c, c).getRGB()); 1243 | } 1244 | 1245 | //------------------------ 1246 | cnt++; 1247 | if (cnt > speed * 10) { 1248 | update(); 1249 | } 1250 | 1251 | if (queue.size() < 1000) { 1252 | if (x < img.getWidth() - 1 && data[x + 1][y][1] <= 0) { 1253 | int ad = (x + 1) * 10000 + y; 1254 | queue.add(ad); 1255 | } 1256 | if (y < img.getHeight() - 1 && data[x][y + 1][1] <= 0) { 1257 | int ad = (x) * 10000 + y + 1; 1258 | queue.add(ad); 1259 | } 1260 | if (x > 0 && data[x - 1][y][1] <= 0) { 1261 | int ad = (x - 1) * 10000 + y; 1262 | queue.add(ad); 1263 | } 1264 | if (y > 0 && data[x][y - 1][1] <= 0) { 1265 | int ad = (x) * 10000 + y - 1; 1266 | queue.add(ad); 1267 | } 1268 | } 1269 | } 1270 | } 1271 | }//dfs stack<1000 用dfs画黑边 1272 | 1273 | 1274 | void proRemove(int x1, int y1, int data[][][], Queue queue, int mode) {//第1次,测定小黑块大小 1275 | int size = 0; 1276 | int maxX = 0, minX = 99999, maxY = 0, minY = 99999, l = 0; 1277 | while (queue.size() > 0) { 1278 | 1279 | size++; 1280 | int a = (int) queue.poll(); 1281 | int x = a / 10000; 1282 | int y = a % 10000; 1283 | 1284 | maxX = Math.max(maxX, x); 1285 | maxY = Math.max(maxY, y); 1286 | minX = Math.min(minX, x); 1287 | minY = Math.min(minY, y); 1288 | l = Math.min(maxX - minX + 8, maxY - minY + 8); 1289 | if ((mode == 0 && data[x][y][0] <= 0 && data[x][y][1] == 0) || (mode == 1 && data[x][y][0] <= 0 && data[x][y][1] == 0 && data[x][y][3] == 1)) { 1290 | data[x][y][1] = -1; 1291 | 1292 | if (x < img.getWidth() - 1 && data[x + 1][y][1] == 0) { 1293 | int ad = (x + 1) * 10000 + y; 1294 | queue.add(ad); 1295 | } 1296 | if (y < img.getHeight() - 1 && data[x][y + 1][1] == 0) { 1297 | int ad = (x) * 10000 + y + 1; 1298 | queue.add(ad); 1299 | } 1300 | if (x > 0 && data[x - 1][y][1] == 0) { 1301 | int ad = (x - 1) * 10000 + y; 1302 | queue.add(ad); 1303 | } 1304 | if (y > 0 && data[x][y - 1][1] == 0) { 1305 | int ad = (x) * 10000 + y - 1; 1306 | queue.add(ad); 1307 | } 1308 | } 1309 | } 1310 | 1311 | 1312 | if (size <= removeBlackPixel || l * l < size * removeBlackPixel2 / 100 + 1) { 1313 | Queue q1 = new LinkedList<>(); 1314 | q1.add(x1 * 10000 + y1); 1315 | proRemove2(data, q1, mode); 1316 | } 1317 | 1318 | }//bfs 1319 | 1320 | 1321 | void proRemove2(int data[][][], Queue queue, int mode) {//第二次,小黑块变白 1322 | 1323 | while (queue.size() > 0) { 1324 | 1325 | int a = (int) queue.poll(); 1326 | int x = a / 10000; 1327 | int y = a % 10000; 1328 | 1329 | // Color color = new Color(0, 0, 0);img.setRGB(x, y, color.getRGB());cnt++;if (cnt > speed*100) { update(); } 1330 | 1331 | if ((mode == 0 && data[x][y][0] <= 0 && data[x][y][1] == -1) || (mode == 1 && data[x][y][0] <= 0 && data[x][y][1] == -1 && data[x][y][3] == 1)) { 1332 | data[x][y][1] = 0; 1333 | if (mode == 0) { 1334 | data[x][y][0] = 1; 1335 | } else { 1336 | data[x][y][3] = 0; 1337 | } 1338 | 1339 | if (x < img.getWidth() - 1 && data[x + 1][y][1] < 0) { 1340 | int ad = (x + 1) * 10000 + y; 1341 | queue.add(ad); 1342 | } 1343 | if (y < img.getHeight() - 1 && data[x][y + 1][1] < 0) { 1344 | int ad = (x) * 10000 + y + 1; 1345 | queue.add(ad); 1346 | } 1347 | if (x > 0 && data[x - 1][y][1] < 0) { 1348 | int ad = (x - 1) * 10000 + y; 1349 | queue.add(ad); 1350 | } 1351 | if (y > 0 && data[x][y - 1][1] < 0) { 1352 | int ad = (x) * 10000 + y - 1; 1353 | queue.add(ad); 1354 | } 1355 | } 1356 | } 1357 | }//bfs 1358 | 1359 | Color pro2(int data[][][], Queue queue, Color color2) { 1360 | long red = 0, blue = 0, green = 0, cnt = 0; 1361 | while (queue.size() > 0) { 1362 | cnt++; 1363 | int a = (int) queue.poll(); 1364 | int x = a / 10000; 1365 | int y = a % 10000; 1366 | Color color = new Color(data[x][y][10]); 1367 | red += color.getRed(); 1368 | green += color.getGreen(); 1369 | blue += color.getBlue(); 1370 | 1371 | if (data[x][y][1] == 0 && data[x][y][0] != 2) { 1372 | data[x][y][1] = 4; 1373 | 1374 | 1375 | Color color1; 1376 | int max = deltaColor; 1377 | if (x < img.getWidth() - 1 && data[x + 1][y][1] == 0) { 1378 | color1 = new Color(data[x + 1][y][10]); 1379 | if (Math.abs(color.getRed() - color1.getRed()) + Math.abs(color.getGreen() - color1.getGreen()) + Math.abs(color.getBlue() - color1.getBlue()) < max) { 1380 | int ad = (x + 1) * 10000 + y; 1381 | queue.add(ad); 1382 | } 1383 | } 1384 | if (y < img.getHeight() - 1 && data[x][y + 1][1] == 0) { 1385 | color1 = new Color(data[x][y + 1][10]); 1386 | if (Math.abs(color.getRed() - color1.getRed()) + Math.abs(color.getGreen() - color1.getGreen()) + Math.abs(color.getBlue() - color1.getBlue()) < max) { 1387 | int ad = (x) * 10000 + y + 1; 1388 | queue.add(ad); 1389 | } 1390 | } 1391 | if (x > 0 && data[x - 1][y][1] == 0) { 1392 | color1 = new Color(data[x - 1][y][10]); 1393 | if (Math.abs(color.getRed() - color1.getRed()) + Math.abs(color.getGreen() - color1.getGreen()) + Math.abs(color.getBlue() - color1.getBlue()) < max) { 1394 | int ad = (x - 1) * 10000 + y; 1395 | queue.add(ad); 1396 | } 1397 | } 1398 | if (y > 0 && data[x][y - 1][1] == 0) { 1399 | color1 = new Color(data[x][y - 1][10]); 1400 | if (Math.abs(color.getRed() - color1.getRed()) + Math.abs(color.getGreen() - color1.getGreen()) + Math.abs(color.getBlue() - color1.getBlue()) < max) { 1401 | int ad = (x) * 10000 + y - 1; 1402 | queue.add(ad); 1403 | } 1404 | } 1405 | } 1406 | } 1407 | cntColor = (int) cnt; 1408 | return new Color((int) (red / cnt), (int) (green / cnt), (int) (blue / cnt)); 1409 | }//bfs 1410 | 1411 | void pro3(int data[][][], Queue queue, Color color3) { 1412 | while (queue.size() > 0) { 1413 | 1414 | int a = (int) queue.poll(); 1415 | int x = a / 10000; 1416 | int y = a % 10000; 1417 | 1418 | if (data[x][y][1] == 4 && data[x][y][0] != 2) { 1419 | data[x][y][1] = 2; 1420 | data[x][y][9] = color3.getRGB(); 1421 | if (new Color(img.getRGB(x, y)).getRed() == 255) 1422 | img.setRGB(x, y, color3.getRGB()); 1423 | else { 1424 | Color colorNow = new Color(img.getRGB(x, y)); 1425 | int r = Math.max(0, colorNow.getRed() + color3.getRed() - 255); 1426 | int g = Math.max(0, colorNow.getGreen() + color3.getGreen() - 255); 1427 | int b = Math.max(0, colorNow.getBlue() + color3.getBlue() - 255); 1428 | Color color4 = new Color(r, g, b); 1429 | if (jParallaxesChooser.getSelectedIndex() == 4) 1430 | img.setRGB(x, y, color4.getRGB() & 0x00ffffff); 1431 | else img.setRGB(x, y, color4.getRGB() ); 1432 | } 1433 | 1434 | cnt++; 1435 | if (cnt > speed * 4500) { 1436 | if (!paintNotPause) 1437 | update(); 1438 | } 1439 | 1440 | 1441 | if (x < img.getWidth() - 1 && data[x + 1][y][1] == 4) { 1442 | int ad = (x + 1) * 10000 + y; 1443 | queue.add(ad); 1444 | 1445 | } 1446 | if (y < img.getHeight() - 1 && data[x][y + 1][1] == 4) { 1447 | int ad = (x) * 10000 + y + 1; 1448 | queue.add(ad); 1449 | 1450 | } 1451 | if (x > 0 && data[x - 1][y][1] == 4) { 1452 | int ad = (x - 1) * 10000 + y; 1453 | queue.add(ad); 1454 | 1455 | } 1456 | if (y > 0 && data[x][y - 1][1] == 4) { 1457 | int ad = (x) * 10000 + y - 1; 1458 | queue.add(ad); 1459 | 1460 | } 1461 | } 1462 | } 1463 | }//bfs 1464 | 1465 | Color getTargetColor(Color colorMap, Color targetColor, Color standardColor, Color colorNow, boolean changeColorWithMap) {//为了得到目标的颜色 1466 | int r = Math.max(0, colorNow.getRed() - standardColor.getRed() + targetColor.getRed()); 1467 | int g = Math.max(0, colorNow.getGreen() - standardColor.getGreen() + targetColor.getGreen()); 1468 | int b = Math.max(0, colorNow.getBlue() - standardColor.getBlue() + targetColor.getBlue()); 1469 | Color color4 = new Color(Math.min(r, 255), Math.min(g, 255), Math.min(b, 255));//替换的颜色 1470 | 1471 | if (changeColorWithMap) {//如果是用贴图换 1472 | if (imgMap != null) { 1473 | //Color colorMap = new Color(imgMap.getRGB(x % imgMap.getWidth(), y % imgMap.getHeight()));//贴图颜色 1474 | if (jParallaxesChooser.getSelectedIndex() == 0) { 1475 | color4 = colorMap; 1476 | } 1477 | if (jParallaxesChooser.getSelectedIndex() == 1) { 1478 | color4 = new Color((colorMap.getRed() + colorNow.getRed()) / 2, (colorMap.getGreen() + colorNow.getGreen()) / 2, (colorMap.getBlue() + colorNow.getBlue()) / 2, colorMap.getAlpha()); 1479 | } 1480 | if (jParallaxesChooser.getSelectedIndex() == 2) { 1481 | r = (int) Math.max(0, (colorMap.getRed() * colorNow.getRed() / 255.0)); 1482 | g = (int) Math.max(0, (colorMap.getGreen() * colorNow.getGreen() / 255.0)); 1483 | b = (int) Math.max(0, (colorMap.getBlue() * colorNow.getBlue() / 255.0)); 1484 | color4 = new Color(r, g, b); 1485 | } 1486 | if (jParallaxesChooser.getSelectedIndex() == 3) { 1487 | r = 255 - (int) ((255 - colorMap.getRed()) * (255 - colorNow.getRed()) / 255.0); 1488 | g = 255 - (int) ((255 - colorMap.getGreen()) * (255 - colorNow.getGreen()) / 255.0); 1489 | b = 255 - (int) ((255 - colorMap.getBlue()) * (255 - colorNow.getBlue()) / 255.0); 1490 | color4 = new Color(r, g, b); 1491 | } 1492 | if (jParallaxesChooser.getSelectedIndex() == 4) { 1493 | int a=255-colorMap.getRed(); 1494 | color4 = new Color(colorNow.getRed()/2, colorNow.getGreen()/2, colorNow.getBlue()/2,a); 1495 | } 1496 | } else { 1497 | //JOptionPane.showMessageDialog(null, "贴图丢失[请先选择贴图]"); 1498 | color4 = new Color(0, 0, 0); 1499 | } 1500 | } 1501 | return color4; 1502 | }//为了得到目标的颜色 1503 | 1504 | void pro3Color(Queue queue, Color targetColor, Color standardColor, boolean changeColorWithMap, boolean mode) {//对块颜色重绘的处理 1505 | 1506 | int data[][][] = new int[img.getWidth()][img.getHeight()][2]; 1507 | Color colorData[][] = new Color[img.getWidth()][img.getHeight()]; 1508 | for (int i = 0; i < img.getWidth(); i++) { 1509 | for (int j = 0; j < img.getHeight(); j++) { 1510 | colorData[i][j] = new Color(img.getRGB(i, j)); 1511 | } 1512 | } 1513 | Queue queueEdge = new LinkedList(); 1514 | while (queue.size() > 0) { 1515 | 1516 | int max = deltaColoring; 1517 | int max2 = deltaColorHue; 1518 | 1519 | 1520 | int a = (int) queue.poll(); 1521 | int x = a / 10000; 1522 | int y = a % 10000; 1523 | if (x >= img.getWidth() || y >= img.getHeight()) continue; 1524 | if (data[x][y][0] == 1) continue; 1525 | Color colorNow = colorData[x][y]; 1526 | 1527 | if (jLimitColorRange.getSelectedIndex() == 1) { 1528 | boolean continueBool = true; 1529 | if (colorNow.getRed() <= Integer.parseInt(r2.getText()) && colorNow.getRed() >= Integer.parseInt(r1.getText())) 1530 | if (colorNow.getGreen() <= Integer.parseInt(g2.getText()) && colorNow.getGreen() >= Integer.parseInt(g1.getText())) 1531 | if (colorNow.getBlue() <= Integer.parseInt(b2.getText()) && colorNow.getBlue() >= Integer.parseInt(b1.getText())) 1532 | if (colorNow.getRed() - colorNow.getGreen() <= Integer.parseInt(rg2.getText()) && colorNow.getRed() - colorNow.getGreen() >= Integer.parseInt(rg1.getText())) 1533 | if (colorNow.getGreen() - colorNow.getBlue() <= Integer.parseInt(gb2.getText()) && colorNow.getGreen() - colorNow.getBlue() >= Integer.parseInt(gb1.getText())) { 1534 | continueBool = false; 1535 | } 1536 | if (continueBool) continue; 1537 | } 1538 | 1539 | 1540 | Color colorMap = new Color(0, 0, 0); 1541 | if (imgMap != null) 1542 | if (jParallaxesPositionChooser.getSelectedIndex() == 1) 1543 | colorMap = new Color(imgMap.getRGB(((x - imgX) + imgMap.getWidth() * 1001 / 2) % imgMap.getWidth(), ((y - imgY) + imgMap.getHeight() * 1001 / 2) % imgMap.getHeight()));//贴图颜色 1544 | else 1545 | colorMap = new Color(imgMap.getRGB(x % imgMap.getWidth(), y % imgMap.getHeight()));//贴图颜色 1546 | 1547 | Color color4 = getTargetColor(colorMap, targetColor, standardColor, colorNow, changeColorWithMap); 1548 | 1549 | 1550 | Color color = new Color(img.getRGB(x, y)); 1551 | Color color1; 1552 | if (jParallaxesChooser.getSelectedIndex() == 4) 1553 | img.setRGB(x, y, 0x00ffffff); 1554 | else img.setRGB(x, y, color4.getRGB() ); 1555 | data[x][y][0] = 1; 1556 | if (!mode) { 1557 | if (x < img.getWidth() - 1 && data[x + 1][y][0] == 0) { 1558 | color1 = new Color(img.getRGB(x + 1, y)); 1559 | 1560 | int rDelta = color.getRed() - color1.getRed(); 1561 | int gDelta = color.getGreen() - color1.getGreen(); 1562 | int bDelta = color.getBlue() - color1.getBlue(); 1563 | int rDeltaS = standardColor.getRed() - color1.getRed(); 1564 | int gDeltaS = standardColor.getGreen() - color1.getGreen(); 1565 | int bDeltaS = standardColor.getBlue() - color1.getBlue(); 1566 | if (Math.abs(rDeltaS - gDeltaS) + Math.abs(gDeltaS - bDeltaS) < max2) 1567 | if (Math.abs(rDelta) + Math.abs(gDelta) + Math.abs(bDelta) < max) { 1568 | int ad = (x + 1) * 10000 + y; 1569 | queue.add(ad); 1570 | } 1571 | int ad = (x + 1) * 10000 + y; 1572 | queueEdge.add(ad); 1573 | } 1574 | if (y < img.getHeight() - 1 && data[x][y + 1][0] == 0) { 1575 | color1 = new Color(img.getRGB(x, y + 1)); 1576 | int rDelta = color.getRed() - color1.getRed(); 1577 | int gDelta = color.getGreen() - color1.getGreen(); 1578 | int bDelta = color.getBlue() - color1.getBlue(); 1579 | int rDeltaS = standardColor.getRed() - color1.getRed(); 1580 | int gDeltaS = standardColor.getGreen() - color1.getGreen(); 1581 | int bDeltaS = standardColor.getBlue() - color1.getBlue(); 1582 | if (Math.abs(rDeltaS - gDeltaS) + Math.abs(gDeltaS - bDeltaS) < max2) 1583 | if (Math.abs(rDelta) + Math.abs(gDelta) + Math.abs(bDelta) < max) { 1584 | int ad = (x) * 10000 + y + 1; 1585 | queue.add(ad); 1586 | } 1587 | int ad = (x) * 10000 + y + 1; 1588 | queueEdge.add(ad); 1589 | } 1590 | if (x > 0 && data[x - 1][y][0] == 0) { 1591 | color1 = new Color(img.getRGB(x - 1, y)); 1592 | int rDelta = color.getRed() - color1.getRed(); 1593 | int gDelta = color.getGreen() - color1.getGreen(); 1594 | int bDelta = color.getBlue() - color1.getBlue(); 1595 | int rDeltaS = standardColor.getRed() - color1.getRed(); 1596 | int gDeltaS = standardColor.getGreen() - color1.getGreen(); 1597 | int bDeltaS = standardColor.getBlue() - color1.getBlue(); 1598 | if (Math.abs(rDeltaS - gDeltaS) + Math.abs(gDeltaS - bDeltaS) < max2) 1599 | if (Math.abs(rDelta) + Math.abs(gDelta) + Math.abs(bDelta) < max) { 1600 | int ad = (x - 1) * 10000 + y; 1601 | queue.add(ad); 1602 | } 1603 | int ad = (x - 1) * 10000 + y; 1604 | queueEdge.add(ad); 1605 | } 1606 | if (y > 0 && data[x][y - 1][0] == 0) { 1607 | color1 = new Color(img.getRGB(x, y - 1)); 1608 | int rDelta = color.getRed() - color1.getRed(); 1609 | int gDelta = color.getGreen() - color1.getGreen(); 1610 | int bDelta = color.getBlue() - color1.getBlue(); 1611 | int rDeltaS = standardColor.getRed() - color1.getRed(); 1612 | int gDeltaS = standardColor.getGreen() - color1.getGreen(); 1613 | int bDeltaS = standardColor.getBlue() - color1.getBlue(); 1614 | if (Math.abs(rDeltaS - gDeltaS) + Math.abs(gDeltaS - bDeltaS) < max2) 1615 | if (Math.abs(rDelta) + Math.abs(gDelta) + Math.abs(bDelta) < max) { 1616 | int ad = (x) * 10000 + y - 1; 1617 | queue.add(ad); 1618 | } 1619 | int ad = (x) * 10000 + y - 1; 1620 | queueEdge.add(ad); 1621 | } 1622 | } 1623 | 1624 | cnt++; 1625 | if (cnt > 8000) { 1626 | update(); 1627 | } 1628 | 1629 | } 1630 | 1631 | while (queueEdge.size() > 0) { 1632 | int a = (int) queueEdge.poll(); 1633 | int x = a / 10000; 1634 | int y = a % 10000; 1635 | if (data[x][y][0] == 1) continue; 1636 | Color colorNow = colorData[x][y]; 1637 | Color colorMap = new Color(0, 0, 0); 1638 | if (imgMap != null) 1639 | if (jParallaxesPositionChooser.getSelectedIndex() == 1) 1640 | colorMap = new Color(imgMap.getRGB(((x - imgX) + imgMap.getWidth() * 1001 / 2) % imgMap.getWidth(), ((y - imgY) + imgMap.getHeight() * 1001 / 2) % imgMap.getHeight()));//贴图颜色 1641 | else 1642 | colorMap = new Color(imgMap.getRGB(x % imgMap.getWidth(), y % imgMap.getHeight()));//贴图颜色 1643 | 1644 | Color color4 = getTargetColor(colorMap, targetColor, standardColor, colorNow, changeColorWithMap); 1645 | 1646 | if (jParallaxesChooser.getSelectedIndex() == 4) 1647 | img.setRGB(x, y, color4.getRGB() & 0x00ffffff); 1648 | else img.setRGB(x, y, color4.getRGB() ); 1649 | 1650 | data[x][y][0] = 1; 1651 | } 1652 | 1653 | 1654 | }//对块颜色重绘的处理 1655 | 1656 | void proColorWithColorRange(Color targetColor, Color standardColor, boolean changeColorWithMap) {//对块颜色重绘的处理 1657 | 1658 | int data[][][] = new int[img.getWidth()][img.getHeight()][2]; 1659 | Color colorData[][] = new Color[img.getWidth()][img.getHeight()]; 1660 | for (int i = 0; i < img.getWidth(); i++) { 1661 | for (int j = 0; j < img.getHeight(); j++) { 1662 | colorData[i][j] = new Color(img.getRGB(i, j)); 1663 | } 1664 | } 1665 | for (int x = 0; x < img.getWidth(); x++) { 1666 | for (int y = 0; y < img.getHeight(); y++) { 1667 | if (data[x][y][0] == 1) continue; 1668 | 1669 | Color colorNow = colorData[x][y]; 1670 | 1671 | 1672 | if (colorNow.getRed() <= Integer.parseInt(r2.getText()) && colorNow.getRed() >= Integer.parseInt(r1.getText())) 1673 | if (colorNow.getGreen() <= Integer.parseInt(g2.getText()) && colorNow.getGreen() >= Integer.parseInt(g1.getText())) 1674 | if (colorNow.getBlue() <= Integer.parseInt(b2.getText()) && colorNow.getBlue() >= Integer.parseInt(b1.getText())) 1675 | if (colorNow.getRed() - colorNow.getGreen() <= Integer.parseInt(rg2.getText()) && colorNow.getRed() - colorNow.getGreen() >= Integer.parseInt(rg1.getText())) 1676 | if (colorNow.getGreen() - colorNow.getBlue() <= Integer.parseInt(gb2.getText()) && colorNow.getGreen() - colorNow.getBlue() >= Integer.parseInt(gb1.getText())) { 1677 | 1678 | Color colorMap = new Color(0, 0, 0); 1679 | if (imgMap != null) 1680 | if (jParallaxesPositionChooser.getSelectedIndex() == 1) 1681 | colorMap = new Color(imgMap.getRGB(((x - imgX) + imgMap.getWidth() * 1001 / 2) % imgMap.getWidth(), ((y - imgY) + imgMap.getHeight() * 1001 / 2) % imgMap.getHeight()));//贴图颜色 1682 | else 1683 | colorMap = new Color(imgMap.getRGB(x % imgMap.getWidth(), y % imgMap.getHeight()));//贴图颜色 1684 | Color color4 = getTargetColor(colorMap, targetColor, standardColor, colorNow, changeColorWithMap); 1685 | if (jParallaxesChooser.getSelectedIndex() == 4) 1686 | img.setRGB(x, y, color4.getRGB() & 0x00ffffff); 1687 | else img.setRGB(x, y, color4.getRGB() ); 1688 | } 1689 | } 1690 | } 1691 | panel.repaint(); 1692 | 1693 | 1694 | }//对选定颜色重绘的处理 1695 | 1696 | void update() { 1697 | 1698 | 1699 | cnt = 0; 1700 | if (speed < 100) 1701 | try { 1702 | Thread.sleep(1); 1703 | } catch (InterruptedException e) { 1704 | e.printStackTrace(); 1705 | } 1706 | panel.repaint(); 1707 | } 1708 | } 1709 | } 1710 | 1711 | 1712 | 1713 | -------------------------------------------------------------------------------- /headPicture.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/headPicture.zip -------------------------------------------------------------------------------- /picturingAI.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/picturingAI.jar -------------------------------------------------------------------------------- /save/Universe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/Universe.png -------------------------------------------------------------------------------- /save/data/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/data/0.jpg -------------------------------------------------------------------------------- /save/data/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/data/1.jpg -------------------------------------------------------------------------------- /save/data/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/data/2.jpg -------------------------------------------------------------------------------- /save/data/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/data/3.jpg -------------------------------------------------------------------------------- /save/data/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/data/4.jpg -------------------------------------------------------------------------------- /save/data/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/data/5.jpg -------------------------------------------------------------------------------- /save/data/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/data/6.jpg -------------------------------------------------------------------------------- /save/last.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/last.jpg -------------------------------------------------------------------------------- /save/yileina.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FanZeros/java/8e0038a78454dae8f6fbd3fdcf61ab3d2a8a3f26/save/yileina.jpg --------------------------------------------------------------------------------