Java:在 JMF Lightweight_Rendered 播放器上绘制线条
我遇到了一个问题:我的应用程序中有一个 JMF-Videoplayer,我想在它上绘图(当视频继续播放时)。我遇到的问题是我使用 JLayeredPane,在 Layer.Content_Layer(index 0) 上添加 VideoPlayer-Control,在 Layer.Modal_Layer(index 300) 上添加 JPanel (setOpaque(false))。
发生的情况是,当我添加 JPanel 时,它不是不透明的,但我看到了绘制的线条,但看不到视频。如果我之前添加 JPanel(没有更改图层的索引),我添加视频控件,然后我会看到视频,但看不到绘制的线条。
有人知道为什么这不起作用以及我如何让它起作用吗?
我考虑过向视频控制组件添加一个 ActionListener,每当图像发生变化时,我都会将此图像绘制为 JPanel 上的背景,但我担心这会花费我宝贵的时间。
我的代码如下所示:
Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
mediaPlayer = Manager.createRealizedPlayer(url);
this.videoPane = new JLayeredPane();
this.videoPane.setLayout(new BorderLayout());
// get the components for the video and the playback controls
this.video = mediaPlayer.getVisualComponent();
this.controls = mediaPlayer.getControlPanelComponent();
this.drawPanel = new JLabel();
this.drawPanel.setSize(video.getWidth(), video.getHeight());
this.drawPanel.setOpaque(false);
if ( video != null )
this.videoPane.add(video, BorderLayout.CENTER, JLayeredPane.FRAME_CONTENT_LAYER);
if ( controls != null )
this.videoPlayerPanel.add( controls, BorderLayout.SOUTH);
this.videoPane.add(drawPanel, BorderLayout.CENTER, JLayeredPane.MODAL_LAYER);
this.videoPlayerPanel.add(videoPane, BorderLayout.CENTER);
videoPlayerPanel 也是一个包含 JLayeredPane 的 JPanel...如您所见。
编辑: 好吧,我进行了一些研究,发现它
mediaPlayer.getVisualComponent();
返回一个 java.awt.Component 并且此类组件不支持不透明度 - 也许这就是我看不到或只能看到 drawPanel 的原因。
因此,目前我正在尝试通过将视频组件添加到自定义面板来直接绘制到视频组件上,在该面板中我重写绘制方法来绘制所有线条。 还有其他想法吗?
I've got a problem: I have a JMF-Videoplayer in my application and I want to draw on it (while the video continues). The Problem I've got is that I use a JLayeredPane where I add the VideoPlayer-Control on Layer.Content_Layer(index 0) and a JPanel (setOpaque(false)) on Layer.Modal_Layer(index 300).
What happens is, when I add the JPanel it is not opaque but I see the drawn lines but not the video. If I add the JPanel before (didn't changed the index of the layer) I add the video-control then I see the video but not the drawn lines.
Has someone an idea why this doesn't work and how I could make it work?
I thought about adding an ActionListener to the video-control-component and evertime the image changes, I take this image and paint it as background on the JPanel but I'm affraid that this will cost me precious time.
My code looks like this:
Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
mediaPlayer = Manager.createRealizedPlayer(url);
this.videoPane = new JLayeredPane();
this.videoPane.setLayout(new BorderLayout());
// get the components for the video and the playback controls
this.video = mediaPlayer.getVisualComponent();
this.controls = mediaPlayer.getControlPanelComponent();
this.drawPanel = new JLabel();
this.drawPanel.setSize(video.getWidth(), video.getHeight());
this.drawPanel.setOpaque(false);
if ( video != null )
this.videoPane.add(video, BorderLayout.CENTER, JLayeredPane.FRAME_CONTENT_LAYER);
if ( controls != null )
this.videoPlayerPanel.add( controls, BorderLayout.SOUTH);
this.videoPane.add(drawPanel, BorderLayout.CENTER, JLayeredPane.MODAL_LAYER);
this.videoPlayerPanel.add(videoPane, BorderLayout.CENTER);
The videoPlayerPanel is also a JPanel that contains the JLayeredPane... as you can see.
Edit:
Okay I put some research into it and found out that
mediaPlayer.getVisualComponent();
returns a java.awt.Component and such components do not support opacity - maybe that's the reason why I cannot see or only see the drawPanel.
So currently I'm trying to draw directly onto the video-Component by adding it to a customized Panel where i override the paint-method to draw all the lines.
Any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过这个问题的答案来回答。
使用 2 个 JInternalFrames,其中轻量级组件位于一个框架上,而重量级 jpanel 位于另一框架上。
answered by the answer to this question.
using 2 JInternalFrames where the lightweight-component is on one frame and the heavyweight-jpanel on the other.