⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capture.java

📁 java的一个可以播放mov文件的播放器编写程序
💻 JAVA
字号:
import java.awt.*;import java.awt.event.*;import java.util.ArrayList;import java.util.Iterator;import java.util.Vector;import java.awt.BorderLayout;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.PrintWriter;import java.awt.BorderLayout;import quicktime.*;import quicktime.io.*;import quicktime.qd.*;import quicktime.std.*;import quicktime.std.movies.*;import quicktime.std.movies.media.*;import quicktime.app.view.*;import quicktime.std.image.*;public class Capture extends Frame implements ActionListener{		static ArrayList<Image> ar1=new ArrayList<Image>();	static ArrayList<Integer> ar2=new ArrayList<Integer>();	static ArrayList<Pict> ar3=new ArrayList<Pict>();				GraphicsImporter tp;	QTComponent qc;	float aspect=(float)4/(float)3;	GraphicsImporter t;	boolean caught=false;	Image javaImage;   	static int index;		Button saveImageButton,	saveDescriptionButton,        deleteButton,		  PicBackButton,	    PicForwardButton,	swapButton;					public Capture(){		Panel buttons = new Panel();	    	    saveImageButton = new Button("SaveImage");	    saveImageButton.addActionListener (this);	    	    saveDescriptionButton = new Button("SaveDescription");	    saveDescriptionButton.addActionListener (this);	    		    deleteButton = new Button ("Delete");	    deleteButton.addActionListener (this);	    	            PicBackButton = new Button ("PicBack");        PicBackButton.addActionListener (this);        PicForwardButton = new Button ("PicForward");        PicForwardButton.addActionListener (this);                swapButton = new Button ("Swap(present&previous)");        swapButton.addActionListener (this);                	    	    buttons.add (saveImageButton);	    buttons.add (saveDescriptionButton);	    	   	    buttons.add (deleteButton);	    	    buttons.add (PicBackButton);        buttons.add (PicForwardButton);        buttons.add (swapButton);	    	    add (buttons, BorderLayout.SOUTH);        	    	    //     Panel pic = new Panel();        	    	    pack();							}						public void capt(Movie mov, int time){								try{			tp=this.getThumbnail(mov,time);							QTComponent qc = QTFactory.makeQTComponent (tp);							ar1.add(javaImage);			ar2.add(mov.getTime());					this.setBounds(0, 500, 1200, 480);		this.setVisible(true);		this.toFront();					} 		catch(Exception ex){}				}public GraphicsImporter getThumbnail(Movie mov, int time){		//		File f= new File(+"gdfg"+".jpeg");//		mpict.writeToFlie(f);								try {			System.out.println("Movie Time" + mov.getTime());                    			Pict mpict = mov.getPict(mov.getTime()); //get PICT from current frame			ar3.add(mpict);			//As there is no constructor to make an image from a PICT we have to //pretend we have a PICT file by adding 512 bytes header to PICT			byte[] newPictBytes = new byte [mpict.getSize() + 512];			mpict.copyToArray (0,  newPictBytes,  512,  newPictBytes.length - 512);			mpict = new Pict (newPictBytes);//get a Dataref to the PICT - structure in movie toolbox			DataRef ref = new DataRef (mpict,  StdQTConstants.kDataRefQTFileTypeTag, "PICT");//make a graphicsImporterDrawer from the dataref to represent an image that is stored as a file //that  can be read and drawn using QuickTime GraphicsImporter component			GraphicsImporterDrawer gid = new GraphicsImporterDrawer(ref);//Create a QTImageProducer from the GraphicsImporterDrawer to produce the image for drawing			QDRect rect = gid.getDisplayBounds();			Dimension dim = new Dimension (rect.getWidth(), rect.getHeight());			aspect = (float)rect.getWidth() / (float)rect.getHeight();			System.out.println("Aspect ratio is " + aspect);			QTImageProducer qtip = new QTImageProducer (gid, dim);					//From the QTImageProducer create a Java image for drawing			javaImage = Toolkit.getDefaultToolkit().createImage(qtip);												caught = true; //stops paint trying to draw a non existant image			repaint();	//calls paint () to display Java image on Java canvas	} catch (QTException ea) { //close down QT because there was a problem			System.out.println("Exception in capture menu");			ea.printStackTrace();			QTSession.close ();				}		return null;                       	      					}	    public void paint(Graphics g) {			      System.out.println("Paint");      if (caught) {	//protect against trying to draw no image			    	      	  System.out.println("Paint after caught");              	      	      	      	  g.drawImage(ar1.get(index),20,50, (int)(aspect * 300.0) , 300, null);						int y=20;													for(int i=0;i<ar1.size();i++){									g.drawImage(ar1.get(i),y,380, (int)(aspect * 60.0) , 60, null);						y=y+120;									}									      }}	public void actionPerformed(ActionEvent e) {				  if (e.getSource() == PicBackButton){          	System.out.println("ffff");			  index=index-1;			  repaint();          }                    else if (e.getSource() == PicForwardButton){                  	          	  index=index+1;        	            	repaint();          }					// TODO Auto-generated method stub		  else if (e.getSource() == deleteButton){                  	          	 ar1.remove(index);        	 ar2.remove(index);        	            	repaint();          }			  else if (e.getSource() == swapButton){    	  	Image a= ar1.get(index);	Image b= ar1.get(index-1);	ar1.remove(index);	ar1.remove(index-1);	ar1.add(index-1,a);	ar1.add(index,b);		int c= ar2.get(index);	int d= ar2.get(index-1);	ar2.remove(index);	ar2.remove(index-1);	ar2.add(index-1,c);	ar2.add(index,d);  			   	repaint(); }	  		  		  		  		  		  else if (e.getSource() == saveImageButton){    	String currentPath = "";	String descriptionFileName = "storyboard.txt";	try	{			int numOfStoryBoard=ar1.size();		if(numOfStoryBoard==0) return;		int count=1;		PrintWriter q = new PrintWriter(new FileOutputStream(currentPath+descriptionFileName), true);		//Iterator i=filerecord.iterator();		q.println("Movie File Name : ");		q.println("Number of storyboard : "+numOfStoryBoard);				//while(i.hasNext())		for(int i=0;i<ar1.size();i++)		{			//Pict afile=(Pict)i.next();			Pict afile = (Pict)ar3.get(i);			//afile.SaveFile(currentPath+String.valueOf(count)+".pict");			try			{								File f=new File(currentPath+String.valueOf(count)+".pict");				afile.writeToFile(f);								System.out.println ("File Saved to - " + f.getAbsolutePath());									}catch(Exception ex){				System.out.println("Error when writing to the file");						}			q.println(count+","+count+".pict");			count++;		}		q.close();	}catch(Exception ex)	{		System.out.println("Error to write file because : "+e);	}	 }	 		  		  		  		  		  		  		  		  		  		  		  		  		  		  		  		  else if (e.getSource() == saveDescriptionButton){		try	{				int count=1;		PrintWriter q = new PrintWriter(new FileOutputStream("c:"+"ImageDescription"), true);		Iterator i=ar1.iterator();		q.println("Movie Name : Assignment2 Movie---Chopsticks");		q.println("Number of pics : "+ar1.size());				while(i.hasNext())		{												q.println(count+","+count+".pict,"+ar2.get(count-1));			count++;		}				q.close();	}catch(Exception ex)	{		System.out.println("Error to write file because : "+e);	}		 	 }		  		  		  		  		  		  			};					}		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -