[Java] JAVA抓取像素设置阴影 →→→→→进入此内容的聊天室

来自 , 2020-02-04, 写在 Java, 查看 144 次.
URL http://www.code666.cn/view/fa3a3c40
  1. /*
  2.  * Copyright (c) 2007, Romain Guy
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  *   * Redistributions of source code must retain the above copyright
  10.  *     notice, this list of conditions and the following disclaimer.
  11.  *   * Redistributions in binary form must reproduce the above
  12.  *     copyright notice, this list of conditions and the following
  13.  *     disclaimer in the documentation and/or other materials provided
  14.  *     with the distribution.
  15.  *   * Neither the name of the TimingFramework project nor the names of its
  16.  *     contributors may be used to endorse or promote products derived
  17.  *     from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.  */
  31. package frc.chapter11.repaintManager;
  32.  
  33. import java.awt.BorderLayout;
  34. import java.awt.Color;
  35. import java.awt.GradientPaint;
  36. import java.awt.Graphics;
  37. import java.awt.Graphics2D;
  38. import java.awt.GridBagConstraints;
  39. import java.awt.GridBagLayout;
  40. import java.awt.Insets;
  41. import java.awt.Rectangle;
  42.  
  43. import javax.swing.JComponent;
  44. import javax.swing.JFrame;
  45. import javax.swing.JPanel;
  46. import javax.swing.SwingUtilities;
  47. import javax.swing.UIManager;
  48. import javax.swing.UnsupportedLookAndFeelException;
  49. import javax.swing.plaf.nimbus.NimbusLookAndFeel;
  50.  
  51. /**
  52.  *
  53.  * @author Romain Guy <romain.guy@mac.com>
  54.  */
  55. public class RepaintManagerDemo extends JFrame {
  56.  
  57.         private ReflectionPanel reflectionPanel;
  58.  
  59.         public RepaintManagerDemo() {
  60.                 super("Repaint Manager Demo");
  61.  
  62.                 setContentPane(new GradientPanel());
  63.                 getContentPane().setLayout(new GridBagLayout());
  64.  
  65.                 add(buildReflectionPanel(), new GridBagConstraints(0, 0, 1, 1, 1.0,
  66.                                 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
  67.                                 new Insets(96, 96, 96, 96), 0, 0));
  68.  
  69.                 pack();
  70.                 setLocationRelativeTo(null);
  71.                 setResizable(false);
  72.  
  73.                 setDefaultCloseOperation(EXIT_ON_CLOSE);
  74.         }
  75.  
  76.         @Override
  77.         public void dispose() {
  78.                 super.dispose();
  79. //              QTSession.close();
  80.         }
  81.  
  82.         private JComponent buildReflectedComponent() {
  83. //              try {
  84. //                      Class.forName("quicktime.QTSession");
  85. //              } catch (ClassNotFoundException ex) {
  86. //                      return new DummyPanel();
  87. //              }
  88. //
  89. //              try {
  90. //                      QTSession.open();
  91. //                      String url = "http://images.apple.com/movies/sony_pictures/spider-man_3/spider-man_3-tlr1_h.480.mov";
  92. //                      DataRef dRef = new DataRef(url);
  93. //                      Movie mov = Movie.fromDataRef(dRef, StdQTConstants.newMovieActive);
  94. //                      MoviePlayer player = new MoviePlayer(mov);
  95. //                      mov.start();
  96. //                      JComponent qtPlayer = QTFactory.makeQTJComponent(player)
  97. //                                      .asJComponent();
  98. //
  99. //                      return qtPlayer;
  100. //              } catch (Exception e) {
  101. //                      return new DummyPanel();
  102. //              }
  103.                 return new DummyPanel();
  104.         }
  105.  
  106.         private JComponent buildReflectionPanel() {
  107.                 reflectionPanel = new ReflectionPanel();
  108.                 reflectionPanel.add(buildReflectedComponent());
  109.  
  110.                 return reflectionPanel;
  111.         }
  112.  
  113.         private static class GradientPanel extends JPanel {
  114.  
  115.                 GradientPanel() {
  116.                         super(new BorderLayout());
  117.                 }
  118.  
  119.                 @Override
  120.                 protected void paintComponent(Graphics g) {
  121.                         Graphics2D g2 = (Graphics2D) g.create();
  122.                         g2.setPaint(new GradientPaint(0.0f, getHeight() * 0.22f, new Color(
  123.                                         0x202737), 0.0f, getHeight() * 0.7f, Color.BLACK, true));
  124.                         Rectangle clip = g.getClipBounds();
  125.                         g2.fillRect(clip.x, clip.y, clip.width, clip.height);
  126.                         g2.dispose();
  127.                 }
  128.         }
  129.  
  130.         public static void main(String[] args) {
  131.                 try {
  132. //                      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
  133.                         UIManager.setLookAndFeel(new NimbusLookAndFeel());
  134. //              } catch (IllegalAccessException ex) {
  135. //                      ex.printStackTrace();
  136. //              } catch (InstantiationException ex) {
  137. //                      ex.printStackTrace();
  138.                 } catch (UnsupportedLookAndFeelException ex) {
  139.                         ex.printStackTrace();
  140. //              } catch (ClassNotFoundException ex) {
  141. //                      ex.printStackTrace();
  142.                 }
  143.  
  144.                 SwingUtilities.invokeLater(new Runnable() {
  145.  
  146.                         @Override
  147.                         public void run() {
  148.                                 new RepaintManagerDemo().setVisible(true);
  149.                         }
  150.                 });
  151.         }
  152. }
  153.  

回复 "JAVA抓取像素设置阴影"

这儿你可以回复上面这条便签

captcha