Java在线视频聊天(3)
//接收
maildata.receive(pack);
ByteArrayInputStream input=new ByteArrayInputStream(data);
Image message=ImageIO.read(input);
//在接收图像窗口显示视频图像
label2.setIcon(new ImageIcon(message));
label.setText("对方IP:"+pack.getAddress()+
" 端口:"+pack.getPort());
}
catch(Exception e)
{
System.out.println("接收图像数据失败!");
}
}
}
else if(Thread.currentThread()==thread2)
{
try
{
//捕获要在播放窗口显示的图象帧
FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl(
"javax.media.control.FrameGrabbingControl");
// 获取当前祯并存入Buffer类
buffer = fgc.grabFrame();
b2i = new BufferToImage( (VideoFormat) buffer.getFormat());
image = b2i.createImage(buffer); //转化为图像
//创建image图像对象大小的图像缓冲区
BufferedImage bi = (BufferedImage) createImage(image.getWidth(null),
image.getHeight(null));
//根据BufferedImage对象创建Graphics2D对象
Graphics2D g2 = bi.createGraphics();
g2.drawImage(image, null, null);
ByteArrayOutputStream output=new ByteArrayOutputStream();
//转换成JPEG图像格式
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( output );
JPEGEncodeParam jpeg = encoder.getDefaultJPEGEncodeParam(bi);
jpeg.setQuality(0.5f,false);
encoder.setJPEGEncodeParam(jpeg);
encoder.encode(bi);
output.close();
InetAddress address=InetAddress.getByName("localhost");
DatagramPacket datapack1=new DatagramPacket(output.toByteArray(),output.size(),教育视频,
address,555);
DatagramSocket maildata1=new DatagramSocket();
maildata1.send(datapack1);
Thread.sleep(400);
}
catch(Exception e)
{
System.out.println("视频发送失败!");
}
}
}
}
public static void main(String args[])
{
new VAplay();
}
}
class TxtChat extends JPanel implements ActionListener,Runnable
{
JPanel p1,p2,p3,p4;
JLabel jpic;
JTextArea txt1,txt2;
JButton btn1,btn2;
JScrollPane scroll,scroll2;
Thread thread;
boolean boo1=false,boo2=false;
TxtChat()
{
setLayout(new BorderLayout());
txt1=new JTextArea();
txt2=new JTextArea();
p1=new JPanel(new GridLayout(2,1));
p2=new JPanel();
p3=new JPanel(new BorderLayout());
jpic=new JLabel(new ImageIcon("image//upload.gif"));
btn1=new JButton("电子文档");
btn2=new JButton("发送信息");
scroll=new JScrollPane(txt1,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>